2
建议先去看文档 快速开始 、常见问题 触发场景描述 跑单元测试读取xlsx文件 触发Bug的代码
这里写代码
```public void readExcel(String path, ReadListener listener) {
ExcelReader excelReader = null;
try {
excelReader = EasyExcel.read(path, listener).build();
ReadSheet readSheet = EasyExcel.readSheet(0).build();
excelReader.read(readSheet);
} catch (IllegalArgumentException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (excelReader != null) {
// 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
excelReader.finish();
}
}
}
----------------------以上是你们demo里的代码--------------
看到异常我先认为是没有指定read的格式,于是我把给excelReader赋值的语句改成了:
excelReader = EasyExcel.read(path, listener).excelType(ExcelTypeEnum.XLSX).build();
但是还是报同样的异常
**提示的异常或者没有达到的效果**
org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException: The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) Documents. You need to call a different part of POI to process this data (eg HSSF instead of XSSF)
at org.apache.poi.openxml4j.opc.internal.ZipHelper.verifyZipHeader(ZipHelper.java:179)
at org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipFile(ZipHelper.java:237)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:134)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:295)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:201)
at com.alibaba.excel.analysis.v07.XlsxSaxAnalyser.readOpcPackage(XlsxSaxAnalyser.java:137)