public FileResult Excel(T_OutStockTaskInfo model) { DividPage page = new DividPage() { CurrentPageShowCounts = 10000000 }; string strErrMsg = string.Empty; List <T_OutStockTaskInfo> lstExport = new List <T_OutStockTaskInfo>(); tfunc_task.GetModelListByPage(ref lstExport, currentUser, model, ref page, ref strErrMsg); //创建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("ERP单号"); row1.CreateCell(3).SetCellValue("任务号"); row1.CreateCell(4).SetCellValue("供应商"); row1.CreateCell(5).SetCellValue("状态"); row1.CreateCell(6).SetCellValue("创建时间"); row1.CreateCell(7).SetCellValue("仓库"); //将数据逐步写入sheet1各个行 for (int i = 0; i < lstExport.Count; i++) { NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1); rowtemp.CreateCell(0).SetCellValue(lstExport[i].StrongHoldName); rowtemp.CreateCell(1).SetCellValue(lstExport[i].StrVoucherType); rowtemp.CreateCell(2).SetCellValue(lstExport[i].ErpVoucherNo); rowtemp.CreateCell(3).SetCellValue(lstExport[i].TaskNo); rowtemp.CreateCell(4).SetCellValue(lstExport[i].SupcusName); rowtemp.CreateCell(5).SetCellValue(lstExport[i].StrStatus); rowtemp.CreateCell(6).SetCellValue(lstExport[i].CreateTime.ToString()); rowtemp.CreateCell(7).SetCellValue(lstExport[i].WareHouseName); } // 写入到客户端 System.IO.MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); ms.Seek(0, SeekOrigin.Begin); return(File(ms, "application/vnd.ms-excel", DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls")); }
public bool GetT_OutTaskListByPage(ref List <T_OutStockTaskInfo> modelList, UserInfo user, T_OutStockTaskInfo t_task, ref DividPage page, ref string strError) { T_OutStockTask_Func tfunc = new T_OutStockTask_Func(); return(tfunc.GetModelListByPage(ref modelList, user, t_task, ref page, ref strError)); }