使用jumboexcel将C#数据表数据导出为excel
问题描述:
在我的项目中,我从数据库获取数据并将其存储在数据表中。从数据表中,我想用jumboexcel将数据导出为excel。请指导我如何实现这一目标。使用jumboexcel将C#数据表数据导出为excel
答
最好的方法是探索JumboExcel github项目中的Demo Tests命名空间。
JumboExcel建立在LINQ的概念,因此,如果您正在使用一个IEnumerable,实体框架的工作,小巧玲珑,或任何类型的数据库客户端的暴露数据集为IEnumerable,得到它与JumboExcel的工作很简单:
var worksheets = new[] {
new WorksheetElement("Persons", new WorksheetParametersElement(false,false),
(from p in db.Persons
order p by p.Name
select new Row(
new InlineString(i.Name),
new InlineString(i.Age)
)
).Take(100000));
// var fileName = @".....\My File.xlsx";
using (var outputStream = new FileStream(fileName, FileMode.CreateNew))
{
OpenXmlBuilder.Write(
outputStream,
worksheets
);
}
+0
请参阅下面的链接:http://csharp.net-informations.com/excel/csharp-excel-oledb.htm 这应该做你想做的。 – ryguy72
欢迎来到Stack Overflow!请通过[tour](http://stackoverflow.com/tour),[帮助中心](http://stackoverflow.com/help)和[如何提出一个好问题](http:// stackoverflow.com/help/how-to-ask)章节,了解本网站的工作原理,并帮助您改善当前和未来的问题,从而帮助您获得更好的答案。 –