/// <summary>
/// 导出流向excel
/// </summary>
/// <returns></returns>
public FileResult ExportDirectionExcel()
{
//创建Excel文件的对象
NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
//添加一个sheet
NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
//给sheet1添加第一行的头部标题
NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
row1.CreateCell(0).SetCellValue("商品编号");
row1.CreateCell(1).SetCellValue("名称");
row1.CreateCell(2).SetCellValue("规格");
row1.CreateCell(3).SetCellValue("包装单位");
row1.CreateCell(4).SetCellValue("生产厂家");
row1.CreateCell(5).SetCellValue("日期");
row1.CreateCell(6).SetCellValue("单位名称");
row1.CreateCell(7).SetCellValue("数量");
row1.CreateCell(8).SetCellValue("单价");
row1.CreateCell(9).SetCellValue("金额");
row1.CreateCell(10).SetCellValue("批号");
row1.CreateCell(11).SetCellValue("有效期");
row1.CreateCell(12).SetCellValue("生产日期");
//将数据逐步写入sheet1各个行
for (int i = 0; i < directionList2.Count; i++)
{
NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);
rowtemp.CreateCell(0).SetCellValue(directionList2[i].Spbh.ToString());
rowtemp.CreateCell(1).SetCellValue(directionList2[i].Spmch.ToString());
rowtemp.CreateCell(2).SetCellValue(directionList2[i].Shpgg.ToString());
rowtemp.CreateCell(3).SetCellValue(directionList2[i].Dw.ToString());
rowtemp.CreateCell(4).SetCellValue(directionList2[i].Shengccj.ToString());
rowtemp.CreateCell(5).SetCellValue(directionList2[i].Rq.ToString());
rowtemp.CreateCell(6).SetCellValue(directionList2[i].Dwmch.ToString());
rowtemp.CreateCell(7).SetCellValue(directionList2[i].Shl.ToString());
rowtemp.CreateCell(8).SetCellValue(directionList2[i].Dj.ToString());
rowtemp.CreateCell(9).SetCellValue(directionList2[i].Je.ToString());
rowtemp.CreateCell(10).SetCellValue(directionList2[i].Pihao.ToString());
rowtemp.CreateCell(11).SetCellValue(directionList2[i].Sxrq.ToString());
rowtemp.CreateCell(12).SetCellValue(directionList2[i].Baozhiqi.ToString());
}
System.IO.MemoryStream ms = new System.IO.MemoryStream();
book.Write(ms);
ms.Seek(0, SeekOrigin.Begin);
string dateTime = DateTime.Now.ToString("yyyy-MM-dd");
string fileName = "查询" + dateTime + ".xls";
return File(ms, "application/vnd.ms-excel", fileName);
}