[alibaba/easyexcel]用模板写入,模板数量过大withTemplate会报错

2024-04-30 296 views
7

问题描述 当withTemplate(templateFileName)使用的模板文件数据量过大时,会报错。我使用的模板文件有17w行数据,我想在模板文件的基础上新增几列新增数据

异常代码

EasyExcel.write(fileName, DemoData.class).withTemplate(templateFileName).sheet().doWrite(data());

异常提示 Create workbook failure com.alibaba.excel.exception.ExcelGenerateException: Create workbook failure at com.alibaba.excel.context.WriteContextImpl.(WriteContextImpl.java:98) at com.alibaba.excel.write.ExcelBuilderImpl.(ExcelBuilderImpl.java:36) at com.alibaba.excel.ExcelWriter.(ExcelWriter.java:36) at com.alibaba.excel.write.builder.ExcelWriterBuilder.build(ExcelWriterBuilder.java:114) at com.deformity.platform.survey.business.common.service.BusinessImportService.importBusinessData$lambda-16(BusinessImportService.kt:285) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: org.apache.poi.util.RecordFormatException: Tried to allocate an array of length 270,579,663, but the maximum length for this record type is 100,000,000. If the file is not corrupt or large, please open an issue on bugzilla to request increasing the maximum allowable size for this record type. As a temporary workaround, consider setting a higher override value with IOUtils.setByteArrayMaxOverride() at org.apache.poi.util.IOUtils.throwRFE(IOUtils.java:599) at org.apache.poi.util.IOUtils.checkLength(IOUtils.java:276) at org.apache.poi.util.IOUtils.toByteArray(IOUtils.java:230) at org.apache.poi.util.IOUtils.toByteArray(IOUtils.java:203) at org.apache.poi.openxml4j.util.ZipArchiveFakeEntry.(ZipArchiveFakeEntry.java:82) at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.(ZipInputStreamZipEntrySource.java:98) at org.apache.poi.openxml4j.opc.ZipPackage.(ZipPackage.java:132) at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:312) at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:59) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:289) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:285) at com.alibaba.excel.util.WorkBookUtil.createWorkBook(WorkBookUtil.java:35) at com.alibaba.excel.context.WriteContextImpl.(WriteContextImpl.java:96) ... 7 common frames omitted

回答

2

是模板文件17W,还是数据17W,模板是可以循环的. 如果方便可否提供文件我来复现

7

这个不行 需要考虑重新读取了 再写入

8

是模板文件17W,还是数据17W,模板是可以循环的. 如果方便可否提供文件我来复现

是模板文件有17w条数据,我要在模板文件的基础上新增一列,在那一列上加内容

1

这个不行 需要考虑重新读取了 再写入

我目前实现的方法就是先读取存到临时数据库里,然后处理完业务逻辑再重新写入。能否支持一下基于大数据量的模板文件新增几列写入数据