//查询数据
Map<String,List> map=cpsEduEvaluateRecordLocalService.getStudentEvaluations(null);
List list=map.get("list");
List sonList=map.get("sonList");
//读取模板复制sheet
InputStream inputStream = this.getClass().getResourceAsStream("/files/StudentEvaluation.xlsx");
ByteArrayOutputStream outT = new ByteArrayOutputStream();
XSSFWorkbook workbook =new XSSFWorkbook(inputStream);
workbook.setSheetName(0,"Sheet0");
for(int i=1;i<5;i++){
workbook.cloneSheet(0,"Sheet"+i);
}
workbook.write(outT);
byte[] bytes=outT.toByteArray();
ByteArrayInputStream bis=new ByteArrayInputStream(bytes);
//EasyExcel读取模板加载数据
ByteArrayOutputStream out = new ByteArrayOutputStream();
ExcelWriter excelWriter = EasyExcel.write(out).withTemplate(bis).build();
WriteSheet writeSheet0 = EasyExcel.writerSheet(0,"Sheet1").build();
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build();
Map<String, Object> map1 = new HashMap<>();
map1.put("name","cdccccccc");
excelWriter.fill(map1, writeSheet0);
excelWriter.finish();
//流下载
String fileName = "学员评价.xlsx";
response.setCharacterEncoding("utf-8");
String newName = URLEncoder.encode(fileName, "UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=\"" + newName + "\"");
response.setContentType("application/x-msdownload");
response.getOutputStream().write(out.toByteArray());
//关闭流
outT.close();
bis.close();
out.close();
EasyExcel动态创建多个工作表
于 2023-12-06 17:17:36 首次发布