您的位置:首页 > 其它

MVC通过NPOI.dll导出word文档

2016-02-01 14:51 204 查看
下载地址:http://download.csdn.net/detail/lilinoscar/9424645

1.首先项目添加并引用:NPOI.dll

2.控制器引用NPOI:

using NPOI.HSSF.UserModel;

using NPOI.SS.UserModel;

3.代码:

public ActionResult ExportData()
{
HSSFWorkbook workbook = new HSSFWorkbook();
ISheet sheet = workbook.CreateSheet("sheet1");
IRow row = null;
ICell cell = null;
row = sheet.CreateRow(0);
cell = row.CreateCell(0);
cell.SetCellValue("数字");
for (int i = 0; i <= 12; i++)
{
row = sheet.CreateRow(i);
cell = row.CreateCell(0);
cell.SetCellValue(i);
}
string fileName ="20160101.xls";
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
return File(ms.ToArray(), "application/ms-excel", fileName);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: