Word的模板导出(参考:https://easyexcel.opensource.alibaba.com/docs/current/quickstart/fill)
- 创建有两个sheet的excel文件模板
- 将模板文件放入resource\templates/doc下
- 使用
public void exportUavInfoExcel(HttpServletResponse response, CaseExportRPO caseExportRPO) throws IOException {response.setContentType("application/vnd.ms-excel");response.setCharacterEncoding("utf-8");response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("无人机情况汇报.xls", "utf-8"));List<Object> caseList = baseMapper.getList();List<UavAreaExcel> typeList = exportStatisticsHandle(typeMap);String templateFileName = new ClassPathResource("templates/doc/uavInfoExcel.xls").getFile().getAbsolutePath();try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(templateFileName).build()) {WriteSheet writeSheet = EasyExcel.writerSheet("按区域").build();excelWriter.fill(areaList, writeSheet);WriteSheet writeSheet1 = EasyExcel.writerSheet("按类型").build();excelWriter.fill(typeList, writeSheet1);Map<String, Object> map = new HashMap<String, Object>();map.put("timeRange", DateUtil.date(caseExportRPO.getStartTime()).toString(DatePattern.CHINESE_DATE_PATTERN) + " 至 " + DateUtil.date(caseExportRPO.getEndTime()).toString(DatePattern.CHINESE_DATE_PATTERN));excelWriter.fill(map, writeSheet);excelWriter.fill(map, writeSheet1);excelWriter.finish();}}