我正在尝试使用POI读取Excel(.xlsx)文件,但是由于某些奇怪的原因,它不断出现以下异常:
java.lang.ClassCastException:org.openxmlformats.schemas.drawingml.x2006.main。 impl.ThemeDocumentImpl 无法转换为org.openxmlformats.schemas.drawingml.x2006.main。 ThemeDocument
我正在使用以下POI 3.7库(系统不允许我们更新)
代码如下。
/**
* @param fileName
* @param outputName
*/
override function parseAndConverToCSVFile(fileName : String, outputName : String) {
var lineCount = 0
var file = new FileInputStream(new File(fileName))
var wb = new XSSFWorkbook(file)
var sheet = wb.getSheetAt(0)
var row : XSSFRow
...
}
创建新工作簿时会引发异常,并显示以下消息。
java.lang.ClassCastException: org.openxmlformats.schemas.drawingml.x2006.main.impl.ThemeDocumentImpl cannot be cast to org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument
at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:39)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:59)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:277)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:186)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:189)
at full.path.package.name.CappingDataImportUtility.parseAndConverToCSVFile(CappingDataImportUtility.gs:57)
我想念什么?