[alibaba/easyexcel]解析Excel2003时抛ExcelAnalysisException

2024-06-20 591 views
3

我的代码: InputStream inputStream =null; try { inputStream = excelFile.getInputStream(); data = EasyExcelFactory.read(inputStream, new Sheet(1, 1, clazz)); inputStream.close(); } catch (IOException e)

解析.xls 格式的文件时,报错: com.alibaba.excel.exception.ExcelAnalysisException: File type error,io must be available markSupported,you can do like this new BufferedInputStream(new FileInputStream(\"/xxxx\")) " at com.alibaba.excel.analysis.ExcelAnalyserImpl.getSaxAnalyser(ExcelAnalyserImpl.java:58) ~[easyexcel-1.1.2-beta4.jar:na] at com.alibaba.excel.analysis.ExcelAnalyserImpl.analysis(ExcelAnalyserImpl.java:72) ~[easyexcel-1.1.2-beta4.jar:na] at com.alibaba.excel.analysis.ExcelAnalyserImpl.analysis(ExcelAnalyserImpl.java:67) ~[easyexcel-1.1.2-beta4.jar:na] at com.alibaba.excel.ExcelReader.read(ExcelReader.java:112) ~[easyexcel-1.1.2-beta4.jar:na] at com.alibaba.excel.EasyExcelFactory.read(EasyExcelFactory.java:38) ~[easyexcel-1.1.2-beta4.jar:na] at com.sf.tcmp.util.ExcelUtil.readExcelFile(ExcelUtil.java:45) ~[tcmp-common-1.0.0.jar:na]

回答

9

使用 new BufferedInputStream(new FileInputStream("/xxxx")) 把inputstream包装一下试试

2

已解决,需要先判断输入文件的格式,如果是2003格式,需要使用 new BufferedInputStream(new FileInputStream("/xxxx")) 把inputstream包装一下。

9

不管什么格式 直接包装一下应该就行可以