再SpringBoot UnitTest中测试easyexcel写入sheet时触发异常. easyexcel版本: 3.2.1
触发Bug的代码 @Test
public void genExcelTest() {
Date startDate = DateTime.now().minusDays(20).toDate();
List<AlertDailySummary> summaryList = alertMessageRecordService.selectSummaryForDaily("all"), startDate);
Assert.assertNotNull(summaryList);
String fileName = "D:\\12.xlsx";
ExcelWriter excelWriter = null;
try {
excelWriter = EasyExcel.write(fileName, AlertSummaryHeadData.class).build();
WriteSheet sheet = EasyExcel.writerSheet("模板").build();
excelWriter.write(summaryList, sheet);
} catch (Exception exception) {
exception.printStackTrace();
} finally {
if (excelWriter != null) {
excelWriter.finish();
}
}
}
提示的异常或者没有达到的效果
com.alibaba.excel.exception.ExcelGenerateException: Can not close IO.
at com.alibaba.excel.context.WriteContextImpl.finish(WriteContextImpl.java:420)
at com.alibaba.excel.write.ExcelBuilderImpl.finish(ExcelBuilderImpl.java:99)
at com.alibaba.excel.write.ExcelBuilderImpl.finishOnException(ExcelBuilderImpl.java:93)
at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:64)
at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:73)
at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:50)
at com.zeekr.platform.alert.platform.service.business.AlertDailySummaryJobTest.genExcelTest(AlertDailySummaryJobTest.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.ExceptionInInitializerError
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.setFeature(TransformerFactoryImpl.java:514)
at org.apache.poi.util.XMLHelper.trySet(XMLHelper.java:265)
at org.apache.poi.util.XMLHelper.getTransformerFactory(XMLHelper.java:219)
at org.apache.poi.util.XMLHelper.newTransformer(XMLHelper.java:226)
at org.apache.poi.openxml4j.opc.StreamHelper.saveXmlInStream(StreamHelper.java:56)
at org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager.saveImpl(ZipContentTypeManager.java:69)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.save(ContentTypeManager.java:452)
at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:520)
at org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1505)
at org.apache.poi.openxml4j.opc.OPCPackage.close(OPCPackage.java:460)
at org.apache.poi.ooxml.POIXMLDocument.close(POIXMLDocument.java:204)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.close(XSSFWorkbook.java:594)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.close(SXSSFWorkbook.java:935)
at com.alibaba.excel.context.WriteContextImpl.finish(WriteContextImpl.java:383)
... 38 more
Caused by: java.lang.NullPointerException
at com.sun.org.apache.xalan.internal.XalanConstants.isJavaVersionAtLeast(XalanConstants.java:259)
at com.sun.org.apache.xalan.internal.XalanConstants.