简体   繁体   English

org.apache.poi.POIXMLException:使用Libre Office更新.xls文件后POI API中的java.lang.reflect.InvocationTargetException

[英]org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException in POI API after an .xls file is updated with Libre Office

I am reading an Excel using POI api, I use the following code to read the excel file. 我正在使用POI api阅读Excel,我使用以下代码来读取excel文件。

    public class ExcelWorkBook {

        private static ExcelWorkBook excelWorkBook = null;
        private static String filePath;
        private static XSSFWorkbook workbook;

        /**
         * This  constructor used to initialize the {@link ExcelWorkBook}
         * @throws IOException
         */
        private ExcelWorkBook() throws IOException {
            try {
                workbook = new XSSFWorkbook(getFile());
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ExcelWorkBook.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        /**
         * This method create a new object {@link ExcelWorkBook}
         * @return {@link ExcelWorkBook}
         * @throws IOException
         */
        public static ExcelWorkBook getInstance() throws IOException {
            excelWorkBook = new ExcelWorkBook();
            return excelWorkBook;
        }

        /**
         * This method create a {@link FileInputStream}
         * @return {@link FileInputStream}
         * @throws FileNotFoundException
         */
        private FileInputStream getFile() throws FileNotFoundException {
          FileInputStream file = new FileInputStream(new File(filePath));
          return file;
        }
        .
        .
        .
        .

But its throwing following exception in a particular file which is created using MS Office 2010 and undated using Libre office. 但它在使用MS Office 2010创建的特定文件中抛出以下异常,并使用Libre office进行了未注明日期。 What could Be the problem. 可能是什么问题呢。 The Stack trace of exception is attached below 下面附有堆栈异常跟踪

 org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
    at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:61) ~[poi-ooxml-3.7.jar:3.7]
    at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:277) ~[poi-ooxml-3.7.jar:3.7]
    at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:282) ~[poi-ooxml-3.7.jar:3.7]
    at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:186) ~[poi-ooxml-3.7.jar:3.7]
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:189) ~[poi-ooxml-3.7.jar:3.7]
    at com.excel.ExcelWorkBook.<init>(ExcelWorkBook.java:48) 
    at com.excel.ExcelWorkBook.getInstance(ExcelWorkBook.java:60) 
    at com.excel.ExcelParser.<init>(ExcelParser.java:64) 
    at com.database.DatabaseLoader.process(DatabaseLoader.java:85) 
    at com.fileuploader.FileUploadHandler.doPost(FileUploadHandler.java:116) 
.
.
.
.
    at java.lang.Thread.run(Thread.java:662) [na:1.6.0_45]
[STDOUT] Caused by: java.lang.reflect.InvocationTargetException: null
[STDOUT]    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.6.0_45]
[STDOUT]    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) ~[na:1.6.0_45]
[STDOUT]    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) ~[na:1.6.0_45]
[STDOUT]    at java.lang.reflect.Constructor.newInstance(Constructor.java:513) ~[na:1.6.0_45]
[STDOUT]    at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:59) ~[poi-ooxml-3.7.jar:3.7]
[STDOUT]    ... 42 common frames omitted
[STDOUT] Caused by: org.apache.xmlbeans.XmlException: error: duplicate attribute 'type'
[STDOUT]    at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3471) ~[xmlbeans-2.3.0.jar:na]
[STDOUT]    at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1270) ~[xmlbeans-2.3.0.jar:na]
[STDOUT]    at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1257) ~[xmlbeans-2.3.0.jar:na]
[STDOUT]    at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345) ~[xmlbeans-2.3.0.jar:na]
[STDOUT]    at org.apache.xmlbeans.XmlObject$Factory.parse(XmlObject.java:663) ~[xmlbeans-2.3.0.jar:2.3.0-r540734]
[STDOUT]    at org.apache.poi.xssf.usermodel.XSSFVMLDrawing.read(XSSFVMLDrawing.java:107) ~[poi-ooxml-3.7.jar:3.7]
[STDOUT]    at org.apache.poi.xssf.usermodel.XSSFVMLDrawing.<init>(XSSFVMLDrawing.java:102) ~[poi-ooxml-3.7.jar:3.7]
[STDOUT]    ... 47 common frames omitted
[STDOUT] Caused by: org.xml.sax.SAXParseException: duplicate attribute 'type'
[STDOUT]    at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.reportFatalError(Piccolo.java:1038) ~[xmlbeans-2.3.0.jar:na]
[STDOUT]    at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:723) ~[xmlbeans-2.3.0.jar:na]
[STDOUT]    at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3439) ~[xmlbeans-2.3.0.jar:na]
[STDOUT]    ... 53 common frames omitted

I had exactly the same exception after I edited with Libe Office a .xlsx file containing comments. 在我使用Libe Office编辑包含注释的.xlsx文件后,我遇到了完全相同的异常。 The removal of the comments solved the issue. 删除评论解决了这个问题。

Your Excel will be parsed into XML first. 您的Excel将首先解析为XML。 This exception happens when the xml is invalid. 当xml无效时会发生此异常。 This can be the case when you create the Excel Sheet with Microsoft Office and then edit the Sheet with some other Software like Libre or Open office. 当您使用Microsoft Office创建Excel工作表,然后使用Libre或Open office等其他软件编辑工作表时,可能会出现这种情况。

I don't know what it is that Open Office or Libre Office do, but they do something to the document that POI doesn't like. 我不知道Open Office或Libre Office是做什么的,但是他们对POI不喜欢的文档做了些什么。

Use Microsoft Excel to read or edit your sheets. 使用Microsoft Excel读取或编辑工作表。 It worked for me, unfortunately. 不幸的是,它对我有用。

I have inserted org.apache.xmlbeans in project. 我在项目中插入了org.apache.xmlbeans。 It helped. 它有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ApachePOI生成org.apache.poi.POIXMLException:java.lang.reflect.InvocationTargetException - ApachePOI generates org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException org.apache.poi.POIXMLException:java.lang.reflect.InvocationTargetException,根本原因是空指针异常(xmlbeans.jar) - org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException,root cause nullpointer exception(xmlbeans.jar) Apache POI工作簿引发java.lang.reflect.InvocationTargetException - Apache POI Workbook throws java.lang.reflect.InvocationTargetException 使用apache poi读取.xlsx文件在linux机器上给出了org.apache.poi.POIXMLException - Reading .xlsx file using apache poi gives org.apache.poi.POIXMLException on linux machine 线程“ main”中的异常org.apache.poi.POIXMLException使用apache POI从xlsx文件读取数据时出现异常 - Exception in thread “main” org.apache.poi.POIXMLException exception appearing while reading data from xlsx file using apache POI org.apache.poi.POIXMLException:org.apache.poi.openxml4j.exceptions.InvalidFormatException: - org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: org.apache.poi.POIXMLException 目前不支持严格的 OOXML,请参阅错误 #57699 - org.apache.poi.POIXMLException Strict OOXML isn't currently supported, please see bug #57699 java.lang.reflect.InvocationTargetException - java.lang.reflect.InvocationTargetException java.lang.reflect.InvocationTargetException? - java.lang.reflect.InvocationTargetException? org.apache.pig.backend.executionengine.ExecException:错误0:java.lang.reflect.InvocationTargetException - org.apache.pig.backend.executionengine.ExecException: ERROR 0: java.lang.reflect.InvocationTargetException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM