[alibaba/easyexcel]com.alibaba.excel.exception.ExcelGenerateException: Can not close IO,本地可以,上到服务器就报错

2024-05-16 779 views
2

建议先去看文档 快速开始常见问题 异常代码

public static void CreateDoubleSheetExcelFile(Class<?> head,Class<?> head1,List<?> data,List<?> data1,String fileName) {
        ExcelWriter excelWriter = null;
        try {
            excelWriter = EasyExcel.write(fileName, head).excelType(ExcelTypeEnum.XLSX).build();
            WriteSheet writeSheet = EasyExcel.writerSheet(0,"每日查询汇总").head(head).build();
            excelWriter.write(data, writeSheet);
            writeSheet = EasyExcel.writerSheet(1,"查询明细").head(head1).build();
            excelWriter.write(data1,writeSheet);
        }catch (Exception e) {
            LOGGER.error("====>>>>>> 生成excel <<<< ==== 异常:{}",e.getMessage());
            e.printStackTrace();
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
    }

异常提示 image 本地windows环境启动可以,上到linux服务器,这句write就报错了,不能关闭IO 建议描述 com.alibaba.excel.exception.ExcelGenerateException: Can not close IO at com.alibaba.excel.context.WriteContextImpl.finish(WriteContextImpl.java:328) ~[easyexcel-2.1.1.jar:na] at com.alibaba.excel.write.ExcelBuilderImpl.finish(ExcelBuilderImpl.java:98) ~[easyexcel-2.1.1.jar:na] at com.alibaba.excel.write.ExcelBuilderImpl.finishOnException(ExcelBuilderImpl.java:92) ~[easyexcel-2.1.1.jar:na] at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:63) ~[easyexcel-2.1.1.jar:na] at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:161) ~[easyexcel-2.1.1.jar:na] at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:146) ~[easyexcel-2.1.1.jar:na] at com.techsun.tracejp.utils.CreateFileUtils.CreateDoubleSheetExcelFile(CreateFileUtils.java:57) ~[classes/:na] at com.techsun.tracejp.manager.impl.SendMailWeeklyManager.sendMailWeekly(SendMailWeeklyManager.java:98) ~[classes/:na] at com.techsun.tracejp.timer.SendMailScheduleTask.sendMailWeekly(SendMailScheduleTask.java:29) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_292] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_292] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_292] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_292] at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) [spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_292] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_292] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_292] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_292] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_292] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_292] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_292] Caused by: org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save: an error occurs while saving the package : Could not load the propery file 'output_xml.properties' for output method 'xml' (check CLASSPATH) at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:595) ~[poi-ooxml-3.17.jar:3.17] at org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1539) ~[poi-ooxml-3.17.jar:3.17] at org.apache.poi.openxml4j.opc.OPCPackage.close(OPCPackage.java:482) ~[poi-ooxml-3.17.jar:3.17] at org.apache.poi.POIXMLDocument.close(POIXMLDocument.java:189) ~[poi-ooxml-3.17.jar:3.17] at org.apache.poi.xssf.streaming.SXSSFWorkbook.close(SXSSFWorkbook.java:909) ~[poi-ooxml-3.17.jar:3.17] at com.alibaba.excel.context.WriteContextImpl.finish(WriteContextImpl.java:286) ~[easyexcel-2.1.1.jar:na] ... 22 common frames omitted Caused by: com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException: Could not load the propery file 'output_xml.properties' for output method 'xml' (check CLASSPATH) at com.sun.org.apache.xml.internal.serializer.OutputPropertiesFactory.getDefaultMethodProperties(OutputPropertiesFactory.java:346) ~[na:1.8.0_292] at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.setDefaults(TransformerImpl.java:1132) ~[na:1.8.0_292] at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.createOutputProperties(TransformerImpl.java:1092) ~[na:1.8.0_292] at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.(TransformerImpl.java:254) ~[na:1.8.0_292] at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.(TransformerImpl.java:245) ~[na:1.8.0_292] at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:735) ~[na:1.8.0_292] at org.apache.poi.openxml4j.opc.StreamHelper.getIdentityTransformer(StreamHelper.java:45) ~[poi-ooxml-3.17.jar:3.17] at org.apache.poi.openxml4j.opc.StreamHelper.saveXmlInStream(StreamHelper.java:61) ~[poi-ooxml-3.17.jar:3.17] at org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller.marshallRelationshipPart(ZipPartMarshaller.java:180) ~[poi-ooxml-3.17.jar:3.17] at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:559) ~[poi-ooxml-3.17.jar:3.17] ... 27 common frames omitted

回答

5

以前项目能跑,正常运行,最近突然报这个错,目前解决了,重启了tomcat就可以了,是部署到tomcat7下的war包项目,排查时发现tomcat其他的war包用到了EasyExcel也是报这个错

8

数据量大就会出现这个问题,求解决