public ActionResult ExportApproverAgentHis(string UserId) { var list = IUserInfoService.ApproverAgentHisLoad(UserId); if (list != null && list.Count > 0) { XSSFWorkbook book = new XSSFWorkbook(); #region var headerStyle = book.CreateCellStyle(); var headerStyle = book.CreateCellStyle(); var headerFontStyle = book.CreateFont(); headerFontStyle.Color = NPOI.HSSF.Util.HSSFColor.White.Index; headerFontStyle.Boldweight = short.MaxValue; headerFontStyle.FontHeightInPoints = 10; headerStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground; headerStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.LightOrange.Index; headerStyle.Alignment = HorizontalAlignment.Center; headerStyle.SetFont(headerFontStyle); #endregion var sheet = book.CreateSheet("report"); var row = sheet.CreateRow(0); #region header sheet.SetColumnWidth(0, 30 * 256); sheet.SetColumnWidth(1, 30 * 256); sheet.SetColumnWidth(2, 30 * 256); sheet.SetColumnWidth(3, 30 * 256); sheet.SetColumnWidth(4, 30 * 256); sheet.SetColumnWidth(5, 30 * 256); sheet.SetColumnWidth(6, 30 * 256); var cell = row.CreateCell(0); cell.SetCellValue("申请人姓名"); cell.CellStyle = headerStyle; cell = row.CreateCell(1); cell.SetCellValue("申请人MUDID"); cell.CellStyle = headerStyle; cell = row.CreateCell(2); cell.SetCellValue("代理人姓名"); cell.CellStyle = headerStyle; cell = row.CreateCell(3); cell.SetCellValue("代理人MUDID"); cell.CellStyle = headerStyle; cell = row.CreateCell(4); cell.SetCellValue("开始日期"); cell.CellStyle = headerStyle; cell = row.CreateCell(5); cell.SetCellValue("结束日期"); cell.CellStyle = headerStyle; cell = row.CreateCell(6); cell.SetCellValue("是否启用"); cell.CellStyle = headerStyle; cell = row.CreateCell(7); cell.SetCellValue("操作人"); cell.CellStyle = headerStyle; cell = row.CreateCell(8); cell.SetCellValue("操作日期"); cell.CellStyle = headerStyle; #endregion #region var dataCellStyle = book.CreateCellStyle(); var dataCellStyle = book.CreateCellStyle(); var dataFontStyle = book.CreateFont(); dataFontStyle.Color = NPOI.HSSF.Util.HSSFColor.Black.Index; dataFontStyle.Boldweight = short.MaxValue; dataFontStyle.FontHeightInPoints = 10; dataCellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground; dataCellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.White.Index; //dataCellStyle.Alignment = HorizontalAlignment.Center; dataCellStyle.SetFont(dataFontStyle); #endregion P_UserDelegateHis disItm; int dataCnt = list.Count; for (int i = 0; i < dataCnt; i++) { disItm = list[i]; row = sheet.CreateRow(1 + i); #region data cell cell = row.CreateCell(0); cell.SetCellValue(disItm.UserName); // 审批人姓名 cell = row.CreateCell(1); cell.SetCellValue(disItm.UserMUDID); //申请人MUDID cell = row.CreateCell(2); cell.SetCellValue(disItm.DelegateUserName); // 代理人姓名 cell = row.CreateCell(3); cell.SetCellValue(disItm.DelegateUserMUDID); // 代理人MUDID cell = row.CreateCell(4); cell.SetCellValue(disItm.StartTime == null ? "" : disItm.StartTime.ToString("yyyy-MM-dd HH:mm:ss")); // 开始日期 cell = row.CreateCell(5); cell.SetCellValue(disItm.EndTime == null ? "" : disItm.EndTime.ToString("yyyy-MM-dd HH:mm:ss")); // 结束日期 cell = row.CreateCell(6); cell.SetCellValue(disItm.IsEnable == 0 ? "否" : "是"); // 是否启用 cell = row.CreateCell(7); cell.SetCellValue(disItm.OperatorMUDID); // 操作人 cell = row.CreateCell(8); cell.SetCellValue(disItm.OperationTime == null ? "" : disItm.OperationTime.ToString("yyyy-MM-dd HH:mm:ss")); // 操作日期 cell = row.CreateCell(9); #endregion } byte[] excelData; using (System.IO.MemoryStream _ms = new System.IO.MemoryStream()) { book.Write(_ms); excelData = _ms.ToArray(); //_ms.Close(); } ViewBag.Msg = "导出成功!"; return(File(excelData, "application/vnd.ms-excel", HttpUtility.UrlEncode("ApproverAgentHis_" + DateTime.Now.ToString("yyyy-MM-dd") + ".xlsx", System.Text.Encoding.UTF8))); } else { ViewBag.Msg = "无符合条件数据!"; return(View()); } }
public JsonResult ApproverAgentHisLoad(string UserId) { var list = IUserInfoService.ApproverAgentHisLoad(UserId); return(Json(new { state = 1, data = list })); }