本文主要是介绍springboot集成easypoi导出多sheet页,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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");}
导出效果:
这篇关于springboot集成easypoi导出多sheet页的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!