public FileResult ExportCreatePromotionRecord(int packageId, string batchCode) { var workbook = new XSSFWorkbook(); var sheet = workbook.CreateSheet(); var row = sheet.CreateRow(0); var cell = null as ICell; var cellNum = 0; row.CreateCell(cellNum++).SetCellValue("批次号"); row.CreateCell(cellNum++).SetCellValue("是否成功"); row.CreateCell(cellNum++).SetCellValue("手机号"); row.CreateCell(cellNum++).SetCellValue("车牌号"); row.CreateCell(cellNum++).SetCellValue("所属大客户"); row.CreateCell(cellNum++).SetCellValue("套餐PID"); row.CreateCell(cellNum++).SetCellValue("套餐名称"); row.CreateCell(cellNum++).SetCellValue("机油升数限制"); row.CreateCell(cellNum++).SetCellValue("塞券人"); row.CreateCell(cellNum++).SetCellValue("塞券时间"); row.CreateCell(cellNum++).SetCellValue("短信配置"); row.CreateCell(cellNum++).SetCellValue("备注"); cellNum = 0; sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); var manager = new VipBaoYangPackageManager(); var packageInfo = manager.SelectPromotionOperationRecord(string.Empty, Guid.Empty, packageId, batchCode, string.Empty, 1, 10).FirstOrDefault(); var promotionRecordInfo = manager.SelectPromotionDetailsByBatchCode(batchCode); if (promotionRecordInfo != null && promotionRecordInfo.Any()) { for (var i = 0; i < promotionRecordInfo.Count; i++) { cellNum = 0; NPOI.SS.UserModel.IRow rowtemp = sheet.CreateRow(i + 1); rowtemp.CreateCell(cellNum++).SetCellValue(promotionRecordInfo[i].BatchCode); rowtemp.CreateCell(cellNum++).SetCellValue(promotionRecordInfo[i].Status == Status.SUCCESS ? "成功" : "失败"); rowtemp.CreateCell(cellNum++).SetCellValue(promotionRecordInfo[i].MobileNumber); rowtemp.CreateCell(cellNum++).SetCellValue(promotionRecordInfo[i].Carno); rowtemp.CreateCell(cellNum++).SetCellValue(packageInfo.VipUserName); rowtemp.CreateCell(cellNum++).SetCellValue(packageInfo.PID); rowtemp.CreateCell(cellNum++).SetCellValue(packageInfo.PackageName); rowtemp.CreateCell(cellNum++).SetCellValue(packageInfo.Volume); rowtemp.CreateCell(cellNum++).SetCellValue(packageInfo.CreateUser); rowtemp.CreateCell(cellNum++).SetCellValue(packageInfo.CreateDateTime.ToString()); rowtemp.CreateCell(cellNum++).SetCellValue(packageInfo.IsSendSms ? "发送" : "不发送"); rowtemp.CreateCell(cellNum++).SetCellValue(promotionRecordInfo[i].Remarks ?? string.Empty); } } var ms = new MemoryStream(); workbook.Write(ms); return(File(ms.ToArray(), "application/x-xls", $"{batchCode}{DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒")}.xlsx")); }