pom文件
<dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-base</artifactId><version>4.1.0</version>
</dependency>
导出模板:
后端代码示例:
/*** 导出加油卡进便利店大额审批列表* @throws IOException */@PreAuthorize("@ss.hasPermi('card:large:export')")@Log(title = "加油卡进便利店大额审批", businessType = BusinessType.EXPORT)@GetMapping("/exportByTemp/{ids}")public AjaxResult exportByTemp(HttpServerResponse response, @PathVariable Long[] ids) throws IOException{TemplateExportParams params = new TemplateExportParams("templates/excel/加油卡进便利店大额审批-导出.xlsx",true);Map<Integer, List<Map<String, Object>>> sheetsMap = new HashMap<>();try {int i = 0;for (Long id : ids) {List<Map<String, Object>> list = new ArrayList<>();Map<String, Object> map = new HashMap<String, Object>();ApprovalprocessCardLarge selectApprovalprocessCardLargeById = approvalprocessCardLargeService.selectApprovalprocessCardLargeById(id);map.put("stationProcess", selectApprovalprocessCardLargeById.getStationProcess());map.put("countyProcess", selectApprovalprocessCardLargeById.getCountyProcess());map.put("cityProcess", selectApprovalprocessCardLargeById.getCityProcess());List<ApprovalprocessCardLargeDetail> detailByLargeId = approvalprocessCardLargeDetailService.getDetailByLargeId(id);map.put("largeList", detailByLargeId);Date reportDate = selectApprovalprocessCardLargeById.getReportDate();String parseDateToStr = DateUtils.parseDateToStr("yyyy-MM-dd", reportDate);map.put("date", parseDateToStr);list.add(map);sheetsMap.put(i++,list);}Workbook wb = ExcelExportUtil.exportExcelClone(sheetsMap, params);FileOutputStream out = new FileOutputStream(StringUtils.getAbsoluteFile("加油卡进便利店大额审批.xlsx"));wb.write(out);IOUtils.closeQuietly(wb);IOUtils.closeQuietly(out);} catch (Exception e) {logger.error("加油卡进便利店大额审批下载失败--->" + e.getMessage());}return AjaxResult.success("加油卡进便利店大额审批.xlsx");}
导出效果: