[alibaba/easyexcel]easyExcel 数据填充, 每次用户点击导出时,条件不同标题头列数就不同, 使用填充模板结合Java代码生成用户制定的标题头的Excel模板,再使用生成的Excel模板,填充数据导出,在生成填充模板时单元格值为{.属性名}时,单元格显示为空

2024-04-25 663 views
7

FillData f1 = new FillData(); f1.setDaKuohao(""); f1.setFirstLayer("{.sa}"); f1.setSecondLayer("s1"); f1.setThirdLayer("t1"); f1.setCloumnPorperty("{.sa}");

FillData f2 = new FillData(); f1.setDaKuohao("{"); f2.setFirstLayer("clou1"); f2.setSecondLayer("s2"); f2.setThirdLayer("t12"); f2.setCloumnPorperty("{.sa}");

List data = new ArrayList<>(); data.add(f1); data.add(f2);

String fileName = TestFileUtil.getPath() + "horizontalFill" + System.currentTimeMillis() + ".xlsx"; // 方案1 try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) { WriteSheet writeSheet = EasyExcel.writerSheet().registerWriteHandler(new FillBgColorStyleCellWriteHandler()).build(); FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build(); excelWriter.fill(data, fillConfig, writeSheet); excelWriter.fill(data, fillConfig, writeSheet); excelWriter.fill(data, fillConfig, writeSheet); Map<String, Object> map = new HashMap<>(); map.put("date", "2019年10月9日13:28:28"); excelWriter.fill(map, writeSheet); }

mmexport1683376625483

回答

0

怎么用easyExcel 填充模板生成填充模板,再利用生成的模板导出数据

1

我建议生成模板的时候直接用List 的write方式为每一行写入效果可能会更好