在C#中使用EPPlus创建Excel报表

作者:V君 发布于:2015-9-7 10:12 Monday 分类:挖坑经验

项目主页:

http://epplus.codeplex.com/

使用示例:

http://zeeshanumardotnet.blogspot.com/2011/06/creating-reports-in-excel-2007-using.html

爆栈好评:

http://stackoverflow.com/questions/2654932/create-excel-files-from-c-sharp-without-office

 

用法:

//创建实例

var excel = new ExcelPackage();

//创建工作表

var wb = excel.Workbook.Worksheets .Add(teamName);

//写表头, 设定列数据样式

wb.Cells[1, 1].Value = "id"; wb.Column(1).Style.Numberformat.Format = "0";

wb.Cells[1, 2].Value = "name";

//写数据

wb.Cells[2, 1].Value = "1";

wb.Cells[2, 2].Value = "zeus";

wb.Cells[2, 1].Value = "2";

wb.Cells[2, 2].Value = "suez";

//自动列宽

wb.Column(i).AutoFit();

//表头字体样式

wb.Cells[1, 1, 1, 2].Style.Font.Bold = true;

//保存

excel.Save(stream);

 

感想:

之前做excel要么用臃肿的interop,要么NPOI这个从java搬过来的东西, 今天抱着试一试的心态再找找, 结果就找到了 EPPlus

用起来感觉还不错!

 

//EOF

标签: 软件开发 C# Office Excel 报表

评论(0) 引用(0) 浏览(2507)

Powered by emlog 去你妹的备案 sitemap