经过测试1.1.2-beta4发现
本地程序一切正常环境eclipse+jdk8,解析服务器端路径文件xlsx文件一切正常,使用如下方法
public static <T extends BaseRowModel> List<T> readExcelWithModel(String fileurl, Class<T> t) {
List<T> datas = new ArrayList<>();
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(fileurl));) {
// 解析每行结果在listener中处理
ExcelListener<T> listener = new ExcelListener<>();
ExcelReader excelReader = new ExcelReader(inputStream, null, listener);
excelReader.read(new Sheet(1, 1, t));
datas = listener.getDatas();
} catch (IOException e) {
e.printStackTrace();
}
return datas;
}
web环境报错
eclipse下jfinal3.5搭建web环境,启动jetty之后,通过controller调用同一个方法访问服务器端的同一个xlsx文件,直接报异常
[ERROR]-[Thread: qtp2092769598-17]-[com.jfinal.core.ActionHandler.handle()]: /yftest
com.alibaba.excel.exception.ExcelAnalysisException: File type error,io must be available markSupported,you can do like this <code> new BufferedInputStream(new FileInputStream(\"/xxxx\"))</code> "
at com.alibaba.excel.analysis.ExcelAnalyserImpl.getSaxAnalyser(ExcelAnalyserImpl.java:58)
at com.alibaba.excel.analysis.ExcelAnalyserImpl.analysis(ExcelAnalyserImpl.java:72)
at com.alibaba.excel.analysis.ExcelAnalyserImpl.analysis(ExcelAnalyserImpl.java:67)
跟踪发现源头是在类com.alibaba.excel.analysis.v07.XlsxSaxAnalyser
public XlsxSaxAnalyser(AnalysisContext analysisContext) throws IOException, OpenXML4JException, XmlException {
this.analysisContext = analysisContext;
analysisContext.setCurrentRowNum(0);
this.xssfReader = new XSSFReader(OPCPackage.open(analysisContext.getInputStream()));
this.sharedStringsTable = this.xssfReader.getSharedStringsTable();
InputStream workbookXml = xssfReader.getWorkbookData();
WorkbookDocument ctWorkbook = WorkbookDocument.Factory.parse(workbookXml);
48行处报异常
org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.WorkbookDocumentImpl cannot be cast to org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument
求助大家,看看有无遇到过同样的问题?
升级poi之后问题不再出现
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.18</version>
</dependency>