对象定义
@ExcelTarget("salesman") @Data public class Salesman { private String id; @Excel(name = "业务员", orderNum = "1", width = 20) private String name; @ExcelCollection(name = "6:00:01-8:30:00", orderNum = "4") private List<TimeCount> timeCount1; @ExcelCollection(name = "8:30:01-12:00:00", orderNum = "4") private List<TimeCount> timeCount2; @ExcelCollection(name = "12:00:01-18:00:00", orderNum = "4") private List<TimeCount> timeCount3; @ExcelCollection(name = "18:00:01-21:00:00", orderNum = "4") private List<TimeCount> timeCount4; @ExcelCollection(name = "21:00:01-6:00:00", orderNum = "4") private List<TimeCount> timeCount5; @ExcelCollection(name = "总计", orderNum = "4") private List<TimeCount> timeCount6; } |
备注:@ExcelCollection表示为集合表格,orderNum指占多少列,为该集合对象导出列的个数。如TimeCount中有6列,列名为拨打量、总案量、接听,可联。对应的@ExcelCollection的name为总计,那么总计对应表格就会合并。
@Data public class TimeCount { private String id; @Excel(name = "拨打量", height = 20, width = 8) private long count_call; @Excel(name = "总案量", height = 20, width = 8) private long count_case; @Excel(name = "接听", height = 20, width = 8) private long listen_count; @Excel(name = "可联", height = 20, width = 8) private long listen_case_count; } |
导出集合封装
List<Salesman> salesmanList = new ArrayList<>(); Iterator<Map.Entry<String, Object>> iter0 = salesmanMap.entrySet().iterator(); while(iter0.hasNext()){ Map.Entry<String, Object> next = iter0.next(); Salesman salesman = new Salesman(); salesman.setName(next.getKey()); Map<String,Object > map = (Map<String, Object>) next.getValue(); TimeCount timeCount6 = new TimeCount(); timeCount6.setCount_case((Integer) map.get("user_count_case")); timeCount6.setListen_case_count((Integer) map.get("user_listen_case_count")); timeCount6.setCount_call((Integer) map.get("user_count_call")); timeCount6.setListen_count((Integer) map.get("user_listen_count")); Map<String,Object> map2 = (Map<String, Object>) map.get("timeFlag"); List<TimeCount> t6 = new ArrayList<>(); t6.add(timeCount6);
List<TimeCount> t1 = new ArrayList<>(); t1.add(getTimeCount((Map<String, Object>) map2.get(1))); List<TimeCount> t2 = new ArrayList<>(); t2.add(getTimeCount((Map<String, Object>) map2.get(2))); List<TimeCount> t3 = new ArrayList<>(); t3.add(getTimeCount((Map<String, Object>) map2.get(3))); List<TimeCount> t4 = new ArrayList<>(); t4.add(getTimeCount((Map<String, Object>) map2.get(4))); List<TimeCount> t5 = new ArrayList<>(); t5.add(getTimeCount((Map<String, Object>) map2.get(5))); salesman.setTimeCount1(t1); salesman.setTimeCount2(t2); salesman.setTimeCount3(t3); salesman.setTimeCount4(t4); salesman.setTimeCount5(t5); salesman.setTimeCount6(t6); salesmanList.add(salesman); }
StringJoiner sj = new StringJoiner(",","总计:",""); sj.add(startDate + " 至 " + endDate).add("业务员" + salesmanList.size() + "人") .add("接听总量"+total_listen_count).add("拨打总量"+total_count_call) .add("可联总案件量"+total_listen_case_count) .add("跟进案件量"+total_count_case);
try { ExportParams exportParams = new ExportParams(sj.toString(), "开案进度表"); Workbook workbook = ExcelExportUtil.exportBigExcel(exportParams, Salesman.class, salesmanList); ExcelExportUtil.closeExportBigExcel(); File successFilePath = new File("E:/urge/开案进度表.xls"); FileOutputStream fos = new FileOutputStream(successFilePath); workbook.write(fos); fos.close(); }catch(IOException e) { e.printStackTrace(); } |
导出效果图
参考内容
https://opensource.afterturn.cn/doc/easypoi.html#90101