[alibaba/easyexcel]用模板导出复杂Excel,列表后面普通变量被覆盖

2024-04-30 585 views
0
异常代码
       public static void downLoadExcel(String fileName, String sourcePath, Map<String, Object> datas, List list,
                                     CellWriteHandler cellWriteHandler, HttpServletResponse response) {
        ExcelWriter excelWriter = null;
        try (InputStream templateInputStream = TemplateExcelUtils.class.getClassLoader().getResourceAsStream(sourcePath)) {
            OutputStream os = TemplateExcelUtils.getOutputStream(fileName,response);
            ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(os).withTemplate(templateInputStream);
            if(ToolUtil.isNotEmpty(cellWriteHandler)){
                excelWriterBuilder = excelWriterBuilder.registerWriteHandler(cellWriteHandler);
            }
            excelWriter = excelWriterBuilder.build();
            // 创建 Sheet
            WriteSheet writeSheet = EasyExcel.writerSheet().build();
            if(ToolUtil.isNotEmpty(list)){
                FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                excelWriter.fill(list, fillConfig, writeSheet);
            }
            // 填充普通变量
            excelWriter.fill(datas, writeSheet);
        } catch (Exception e) {
            e.printStackTrace();
            throw new SysException("导出数据失败",null);
        }finally {
            if(excelWriter != null){
                excelWriter.finish();
            }
        }
    }
异常提示

我的模板 1678096136795 导出结果 1678096383787

问题描述

导出后,最后一行的数据不见了

回答

3

+1 跟你的问题一样

0

forceNewRow(Boolean.TRUE)试一下

1

forceNewRow(Boolean.TRUE)试一下

1678115371550 设置了