easypoi官方文档
implementation group: 'cn.afterturn', name: 'easypoi-spring-boot-starter', version: '4.1.0'
public void download(HttpServletResponse response, String schoolName,
String start,
String end,
Integer subject){
List<Map<String, Object>> exportParamList = new ArrayList<>();
List<Object[]> forRanks = woSchoolRepo.getForRankNoPage(schoolName, subject, start, end);
List<RespRanks> list1 = new ArrayList<>();
for (Object[] forRank : forRanks) {
RespRanks build = RespRanks.builder()
.gradeName(forRank[0] + "")
.className(forRank[1] + "")
.excellent(((BigDecimal) forRank[2]).intValue())
.good(((BigDecimal) forRank[3]).intValue())
.pass(((BigDecimal) forRank[4]).intValue())
.fail(((BigDecimal) forRank[5]).intValue()).build();
list1.add(build);
}
log.info("list1: "+list1);
ExportParams params = new ExportParams("成绩汇总", "班级成绩汇总", ExcelType.XSSF);
Map<String, Object> valueMap = Maps.newHashMap();
valueMap.put("title", params);
valueMap.put("data", list1);
valueMap.put("entity", RespRanks.class);
exportParamList.add(valueMap);
List<WoSchool> all = woSchoolRepo.findAllBySubjectIdAndSchoolNameAndClientTimeIsBetween(subject, schoolName, DateUtil.getDateformString(start), DateUtil.getDateformString(end));
List<RespStudents> list2 = all.stream().map(RespStudents::convert).collect(Collectors.toList());
log.info("list2: "+list2);
ExportParams params2 = new ExportParams("成绩汇总", "个人成绩汇总", ExcelType.XSSF);
Map<String, Object> valueMap2 = Maps.newHashMap();
valueMap2.put("title", params2);
valueMap2.put("data", list2);
valueMap2.put("entity", RespStudents.class);
exportParamList.add(valueMap2);
try {
Workbook workbook = ExcelExportUtil.exportExcel(exportParamList, ExcelType.XSSF);
response.setContentType("application/xlsx;charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename=" + System.currentTimeMillis()+".xlsx");
workbook.write(response.getOutputStream());
}catch (Exception e){
e.printStackTrace();
}
}