2017-02-15 98 views
0

我想讀使用Apache POI .xlsx文件,但錯誤我擊中:錯誤的
閱讀.xlsx文件給出的InvocationTargetException

org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException 

完整堆棧跟蹤說:

org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException 
    at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:63) 
    at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:625) 
    at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:637) 
    at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:186) 
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:290) 
    at com.gemini.util.WorkbookObject.createExcelObj(WorkbookObject.java:77) 
    at com.gemini.util.ObjectPool.prepareList(ObjectPool.java:24) 
    at com.gemini.util.WorkbookObject.getInstance(WorkbookObject.java:36) 
    at dhfl_idecimal.decimal_dhfl.calculator.Calculator.processWealthPlusAce(Calculator.java:33) 
    at dhfl_idecimal.decimal_dhfl.calculator.Calculator.main(Calculator.java:167) 
Caused by: java.lang.reflect.InvocationTargetException 
    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:56) 
    at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:60) 
    ... 9 more 
Caused by: org.apache.xmlbeans.XmlException: Attribute "type" was already specified for element "v:shape". 
    at org.apache.poi.xssf.usermodel.XSSFVMLDrawing.read(XSSFVMLDrawing.java:138) 
    at org.apache.poi.xssf.usermodel.XSSFVMLDrawing.<init>(XSSFVMLDrawing.java:121) 
    ... 15 more 
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 549; Attribute "type" was already specified for element "v:shape". 
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) 
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177) 
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400) 
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327) 
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284) 
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:327) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602) 
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:841) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770) 
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) 
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243) 
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339) 
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) 
    at org.apache.poi.util.DocumentHelper.readDocument(DocumentHelper.java:137) 
    at org.apache.poi.xssf.usermodel.XSSFVMLDrawing.read(XSSFVMLDrawing.java:136) 
    ... 16 more 
java.lang.NullPointerException 
    at dhfl_idecimal.decimal_dhfl.calculator.util.UpdateInput.updateInputParamForWealthPlusAce(UpdateInput.java:23) 
    at dhfl_idecimal.decimal_dhfl.calculator.Calculator.processWealthPlusAce(Calculator.java:38) 
    at dhfl_idecimal.decimal_dhfl.calculator.Calculator.main(Calculator.java:167) 

PS:我提到了thisthis的問題,但沒有幫助。

我也試過添加org.apache.xmlbeans罐子,但沒有運氣。

+0

您可以添加您的代碼片段,它讀取.xlsx文件? –

回答

0

找到了答案。不是一個確切的解決方案,但工作
我的代碼沒有錯,因爲我試着閱讀其他的excel,它的工作完美無瑕。問題在於excel。
可能的原因: 首先將excel解析爲XML,當XML無效時會出現此錯誤。我的excel主要是使用MS-Office(Windows環境)開發的,我使用Libra Calc(在Linux環境下)編輯它,所以這可能是poi無法正確讀取excel的原因。
解決方案:剛剛在Linux環境下開發出了同樣的excel,因爲它運行良好。