[alibaba/easyexcel]读取xls后缀文件报LeftoverDataException异常,另存为xlsx格式读取没问题

2024-05-23 959 views
3

异常代码

        String fileName = TestFileUtil.getPath() + "valuation" + File.separator + "中证信托-结构化配资.xls";
        LOGGER.info("fileName:" + fileName);
/*        // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(fileName, ValuationData.class, new DemoReadValuationListener()).sheet().headRowNumber(4).doRead();*/

        try {
            InputStream inputStream = new FileInputStream(fileName);
            AnalysisParam param = new AnalysisParam(inputStream, null, new ValuationData());
            param.setIn(inputStream);
            param.setExcelTypeEnum( ExcelTypeEnum.XLS );
            ExcelReader excelReader = new ExcelReader(param, new DemoReadValuationListener());
            excelReader.read(new Sheet(1,4));

/*            Assert.assertEquals(excelReader.getSheets().size(), 3);
            Assert.assertTrue(excelReader.getAnalysisContext() != null);*/
            inputStream.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            // 记录日志 (可选)
            // 抛出异常(可选)
        }

异常提示 LeftoverDataException DemoReadValuationTest com.alibaba.easyexcel.test.demo.valuation.DemoReadValuationTest valuationSimpleRead(com.alibaba.easyexcel.test.demo.valuation.DemoReadValuationTest) org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x31(FontRecord) left 4 bytes remaining still to be read.

at org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:178)

at org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:235)

at org.apache.poi.hssf.eventusermodel.HSSFEventFactory.genericProcessEvents(HSSFEventFactory.java:175)

at org.apache.poi.hssf.eventusermodel.HSSFEventFactory.processEvents(HSSFEventFactory.java:136)

at org.apache.poi.hssf.eventusermodel.HSSFEventFactory.processWorkbookEvents(HSSFEventFactory.java:82)

at org.apache.poi.hssf.eventusermodel.HSSFEventFactory.processWorkbookEvents(HSSFEventFactory.java:54)

at com.alibaba.excel.analysis.v03.XlsSaxAnalyser.execute(XlsSaxAnalyser.java:112)

at com.alibaba.excel.analysis.ExcelAnalyserImpl.analysis(ExcelAnalyserImpl.java:105)

at com.alibaba.excel.ExcelReader.read(ExcelReader.java:180)

at com.alibaba.excel.ExcelReader.read(ExcelReader.java:170)

at com.alibaba.excel.ExcelReader.read(ExcelReader.java:202)

at com.alibaba.easyexcel.test.demo.valuation.DemoReadValuationTest.valuationSimpleRead(DemoReadValuationTest.java:46)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

建议描述 把excle文件 另存为 ,选择XLSX格式就不存在这个问题。但是实际客户原样的就是XLS后缀文件

回答

8

这个需要提供具体文件