简体   繁体   English

线程“ 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

Please find below the code..... 请在下面的代码中找到.....

package sanityTests;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

public class ApachePOI {

    public static void main(String[] args) throws Exception {

        File src = new File("C:/Users/Ishan/Desktop/TestData.xlsx");
        FileInputStream fis = new FileInputStream(src);
        XSSFWorkbook wb = new XSSFWorkbook(fis);   // To deal with XLSX workbook 
        //HSSFWorkbook wb1 = new HSSFWorkbook(fis1);   // To deal with XLS workbook

        XSSFSheet sheet1 =wb.getSheetAt(0);
        String data0 = sheet1.getRow(0).getCell(0).getStringCellValue();
        System.out.println(data0);
        wb.close();
    }
}

While running the program I am getting the following issue:- 运行该程序时,出现以下问题:

Exception in thread "main" org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
    at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:65)
    at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:601)
    at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:174)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:279)
    at sanityTests.ApachePOI.main(ApachePOI.java:20)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56)
    at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:62)
    ... 4 more
Caused by: java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.setLoadEntityBytesLimit(I)Lorg/apache/xmlbeans/XmlOptions;
    at org.apache.poi.POIXMLTypeLoader.<clinit>(POIXMLTypeLoader.java:50)
    at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:85)
    ... 10 more

If I change the format of the file from xlsx to xls it works fine.Not sure how to resolve the error. 如果我将文件格式从xlsx更改为xls,则可以正常工作。不确定如何解决该错误。 I have included all the jars like xml-beans and poi jars. 我已经包括了所有的xml-beans和poi罐子。 Still getting the error. 仍然出现错误。 Please help 请帮忙

You haven't provided any version numbers for any of your components. 您尚未为任何组件提供任何版本号。 However, XmlOptions.setLoadEntityBytesLimit(int) was only added in XMLBeans version 2.6.0 (from August 2012), and will not be present in 2.4.0. 但是, XmlOptions.setLoadEntityBytesLimit(int)仅在XMLBeans 版本2.6.0 (自2012年8月起)中添加,在2.4.0中不存在。

As far as I can tell, POI has used 2.6.0 itself for quite a long time, but somehow an older version of the library has been included in your runtime dependencies, and will need updating. 据我所知,POI长时间使用2.6.0本身,但是以某种方式,库的旧版本已包含在运行时依赖项中,并且需要更新。

To sum up: include XMLBeans 2.6.0 in your project and POI will work fine. 总结:在您的项目中包含XMLBeans 2.6.0,POI可以正常工作。

暂无
暂无

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

相关问题 使用apache poi读取.xlsx文件在linux机器上给出了org.apache.poi.POIXMLException - Reading .xlsx file using apache poi gives org.apache.poi.POIXMLException on linux machine 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读取xlsx时主线程中的NoSuchMethodError - NoSuchMethodError in main thread while reading xlsx using apache poi Apache POI 在 Linux 环境下读取 xlsx 文件时抛出异常 - Apache POI throws exception while reading xlsx file in Linux enviroment 使用Apache POI读取xlsx文件时出现异常(org.apache.poi.openxml4j.exceptions.InvalidFormatException:日期格式不正确,…)? - Exception(org.apache.poi.openxml4j.exceptions.InvalidFormatException: Date not well formated, …) when reading 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:使用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 用apache poi读取Excel文件时出现异常 - exception while reading Excel file with apache poi 使用 Apache POI 读取 xlsx 文件时出现异常(org.apache.poi.openxml4j.exception - 无内容类型 [M1.13])? - Getting Exception(org.apache.poi.openxml4j.exception - no content type [M1.13]) when reading xlsx file using Apache POI? apache POI 在读取 xlsx 文件时出现异常 - apache POI exception in reading xlsx files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM