/// <summary> /// 获取兑换码 /// </summary> /// <param name="batchCode"></param> /// <param name="packId"></param> /// <returns></returns> public ActionResult DownloadRedemptionCode(string batchCode, long packId) { var manager = new VipBaoYangPackageManager(); var result = manager.GetRedemptionCodeDetails(batchCode, packId, User.Identity.Name); 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("有效截至时间"); cellNum = 0; sheet.SetColumnWidth(cellNum++, 20 * 256); sheet.SetColumnWidth(cellNum++, 28 * 256); sheet.SetColumnWidth(cellNum++, 28 * 256); var rowNumber = 1; result.ForEach(x => { cellNum = 0; row = sheet.CreateRow(rowNumber); row.CreateCell(cellNum++).SetCellValue(x.RedemptionCode); row.CreateCell(cellNum++).SetCellValue(x.StartTime.ToString("yyyy-MM-dd HH:mm:ss")); row.CreateCell(cellNum++).SetCellValue(x.EndTime.ToString("yyyy-MM-dd HH:mm:ss")); rowNumber++; }); 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")); }