首页 > 其他 > 详细

学习笔记导出

时间:2017-11-16 18:04:02      阅读:215      评论:0      收藏:0      [点我收藏+]

//获取数据库数据
var list = new BLL.Wbll().Show().ToList();

//创建Excel文件的对象
HSSFWorkbook book = new HSSFWorkbook();
//添加一个文件薄
ISheet sheet = book.CreateSheet("sheet1");
//设置初始行
IRow row = sheet.CreateRow(0);
//给文件薄添加头部标题
row.CreateCell(0).SetCellValue("编号");
row.CreateCell(1).SetCellValue("文件名称");
row.CreateCell(2).SetCellValue("文件格式");
row.CreateCell(3).SetCellValue("上传时间");
//将数据逐步写入sheet行
for (int i = 0; i <list.Count ; i++)
{
IRow row1 = sheet.CreateRow(i + 1);
row1.CreateCell(0).SetCellValue(list[i].Wid.ToString());
row1.CreateCell(1).SetCellValue(list[i].Wname);
row1.CreateCell(2).SetCellValue(list[i].Wtype);
row1.CreateCell(3).SetCellValue(list[i].Wtime.ToString());
}
//创建写入流
MemoryStream ms = new MemoryStream();
//写入流
book.Write(ms);
ms.Seek(0, SeekOrigin.Begin);
return File(ms, "application/vnd.ms-excel", "导出数据.xls");

学习笔记导出

原文:http://www.cnblogs.com/w-pengchao/p/7845167.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!