alibaba / easyexcel

快速、简洁、解决大文件内存溢出的java处理Excel工具
https://easyexcel.opensource.alibaba.com
Apache License 2.0
32.69k stars 7.58k forks source link

运行报错:java.lang.IllegalArgumentException: Invalid cell range, having lastRow < firstRow || lastCol < firstCol, had rows -1 >= -1 or cells 0 >= 16383 #4004

Open luojunpeng1995 opened 1 month ago

luojunpeng1995 commented 1 month ago

触发场景描述

使用模板导出excel,参考官方的模板代码,做了一些数据的填充调整 我的pom版本:

com.alibaba easyexcel 4.0.3

我根据报错的位置坐了debug,截图如下: 微信图片_20240924144959

代码如下:

触发Bug的代码

public static void main(String[] args) {
        String template = "C:\\Users\\jp\\Desktop\\demo2.xlsx";
        String fileName = "C:\\Users\\jp\\Desktop\\aaa.xlsx";
        Map<String, String> m = new HashMap<>();
        m.put("no", "123");
        m.put("name", "456");
        List<Map<String, String>> list = new ArrayList<>();
        list.add(m);
        try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(template).build()) {
            WriteSheet writeSheet = EasyExcel.writerSheet().build();
            FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
            // 如果有多个list 模板上必须有{前缀.} 这里的前缀就是 data1,然后多个list必须用 FillWrapper包裹
            excelWriter.fill(new FillWrapper("data1", list), fillConfig, writeSheet);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("date", new Date());
            map.put("no", "1234566");
            excelWriter.fill(map, writeSheet);
        }
    }
14:44:33.302 [main] DEBUG com.alibaba.excel.metadata.property.ExcelHeadProperty - The initialization sheet/table 'ExcelHeadProperty' is complete , head kind is NONE
14:44:33.305 [main] DEBUG com.alibaba.excel.context.WriteContextImpl - CurrentConfiguration is writeSheetHolder
14:44:33.350 [main] DEBUG com.alibaba.excel.context.WriteContextImpl - Sheet:null,null is already existed
14:44:33.350 [main] DEBUG com.alibaba.excel.context.WriteContextImpl - CurrentConfiguration is writeSheetHolder
14:44:33.363 [main] INFO com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder - create new style:com.alibaba.excel.write.metadata.style.WriteCellStyle@f7f17e5c,null
14:44:33.369 [main] INFO com.alibaba.excel.util.StyleUtil - create new data fromat:com.alibaba.excel.metadata.data.DataFormatData@4f770922
14:44:33.370 [main] INFO com.alibaba.excel.util.StyleUtil - create new font:com.alibaba.excel.write.metadata.style.WriteFont@96caf36,null
14:44:33.385 [main] DEBUG org.apache.poi.xssf.streaming.SXSSFSheet - Failed to set dimension details on sheet
java.lang.IllegalArgumentException: Invalid cell range, having lastRow < firstRow || lastCol < firstCol, had rows -1 >= -1 or cells 0 >= 16383
    at org.apache.poi.ss.util.CellRangeAddress.<init>(CellRangeAddress.java:48)
    at org.apache.poi.xssf.streaming.SXSSFSheet.deriveDimension(SXSSFSheet.java:2190)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.flushSheets(SXSSFWorkbook.java:994)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.write(SXSSFWorkbook.java:938)
    at com.alibaba.excel.context.WriteContextImpl.finish(WriteContextImpl.java:381)
    at com.alibaba.excel.write.ExcelBuilderImpl.finish(ExcelBuilderImpl.java:99)
    at com.alibaba.excel.ExcelWriter.finish(ExcelWriter.java:143)
    at com.alibaba.excel.ExcelWriter.close(ExcelWriter.java:158)
    at com.junpeng.testmysql.PrintTest.main(PrintTest.java:46)
14:44:33.385 [main] DEBUG org.apache.poi.xssf.streaming.SXSSFSheet - Failed to set dimension details on sheet
java.lang.IllegalArgumentException: Invalid cell range, having lastRow < firstRow || lastCol < firstCol, had rows -1 >= -1 or cells 0 >= 16383
    at org.apache.poi.ss.util.CellRangeAddress.<init>(CellRangeAddress.java:48)
    at org.apache.poi.xssf.streaming.SXSSFSheet.deriveDimension(SXSSFSheet.java:2190)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.flushSheets(SXSSFWorkbook.java:994)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.write(SXSSFWorkbook.java:938)
    at com.alibaba.excel.context.WriteContextImpl.finish(WriteContextImpl.java:381)
    at com.alibaba.excel.write.ExcelBuilderImpl.finish(ExcelBuilderImpl.java:99)
    at com.alibaba.excel.ExcelWriter.finish(ExcelWriter.java:143)
    at com.alibaba.excel.ExcelWriter.close(ExcelWriter.java:158)
    at com.junpeng.testmysql.PrintTest.main(PrintTest.java:46)
14:44:33.385 [main] DEBUG org.apache.poi.xssf.streaming.SXSSFSheet - Failed to set dimension details on sheet
java.lang.IllegalArgumentException: Invalid cell range, having lastRow < firstRow || lastCol < firstCol, had rows -1 >= -1 or cells 0 >= 16383
    at org.apache.poi.ss.util.CellRangeAddress.<init>(CellRangeAddress.java:48)
    at org.apache.poi.xssf.streaming.SXSSFSheet.deriveDimension(SXSSFSheet.java:2190)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.flushSheets(SXSSFWorkbook.java:994)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.write(SXSSFWorkbook.java:938)
    at com.alibaba.excel.context.WriteContextImpl.finish(WriteContextImpl.java:381)
    at com.alibaba.excel.write.ExcelBuilderImpl.finish(ExcelBuilderImpl.java:99)
    at com.alibaba.excel.ExcelWriter.finish(ExcelWriter.java:143)
    at com.alibaba.excel.ExcelWriter.close(ExcelWriter.java:158)
    at com.junpeng.testmysql.PrintTest.main(PrintTest.java:46)
14:44:33.428 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save content types part
14:44:33.498 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save package relationships
14:44:33.502 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save part 'docProps/app.xml'
14:44:33.503 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save part 'docProps/core.xml'
14:44:33.505 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save part 'docProps/custom.xml'
14:44:33.505 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save part 'xl/sharedStrings.xml'
14:44:33.505 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save part 'xl/styles.xml'
14:44:33.506 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save part 'xl/theme/theme1.xml'
14:44:33.506 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save part 'xl/workbook.xml'
14:44:33.508 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save part 'xl/worksheets/sheet1.xml'
14:44:33.509 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save part 'xl/worksheets/sheet2.xml'
14:44:33.509 [main] DEBUG org.apache.poi.openxml4j.opc.ZipPackage - Save part 'xl/worksheets/sheet3.xml'
14:44:33.543 [main] DEBUG com.alibaba.excel.context.WriteContextImpl - Finished write.

代码可以正常运行,且可以达到填充并且正常的生成excel,但是运行过程中会出现以下错误日志,希望维护人员帮忙解决一下,非常感谢。

youlingdada commented 1 month ago

方便提供一下excel模板文件吗,用于复现错误

luojunpeng1995 commented 1 month ago

demo2.xlsx 不好意思 这段时间比较忙 没有来看

xrayw commented 1 week ago

+1, 同遇到了. 我按照这里的填充列表demo, 遇到了相同的问题.

问题版本: 4.0.3, 我退回到3.3.4 又能正常运行, 没这个问题.

image