/// <summary> /// 导出数据至Excel /// </summary> /// <returns></returns> public ActionResult ExportExcel(int packageId = 0) { 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("PID"); 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++, 14 * 256); sheet.SetColumnWidth(cellNum++, 8 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 50 * 256); sheet.SetColumnWidth(cellNum++, 50 * 256); sheet.SetColumnWidth(cellNum++, 28 * 256); var manager = new PaintDiscountConfigManager(); var packageName = string.Empty; if (packageId > 0) { var package = manager.GetPaintDiscountPackage(packageId); if (package == null) { return(Json(new { Status = false, Msg = "未知的喷漆打折价格体系" }, JsonRequestBehavior.AllowGet)); } else { packageName = package.PackageName; } } var result = manager.GetPaintDiscountDetailByPackageId(packageId); if (result != null && result.Any()) { int modelRowCount = 1; foreach (var model in result) { int modelCol = 0; var modelRow = sheet.CreateRow(modelRowCount); modelRow.CreateCell(modelCol++).SetCellValue(model.ServicePid); modelRow.CreateCell(modelCol++).SetCellValue(model.SurfaceCount); modelRow.CreateCell(modelCol++).SetCellValue((double)model.ActivityPrice); modelRow.CreateCell(modelCol++).SetCellValue(model.ActivityName); modelRow.CreateCell(modelCol++).SetCellValue(model.ActivityExplain); modelRow.CreateCell(modelCol++).SetCellValue(model.ActivityImage); modelRowCount++; } } var ms = new MemoryStream(); workbook.Write(ms); return(File(ms.ToArray(), "application/x-xls", $"喷漆打折价格体系{packageName}的服务价格配置 {DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒")}.xlsx")); }