skip to Main Content

Context:

Trying to open XLSX file using Apache POI’s poi & poi-ooxml 4.0.0 version jar’s

Issue:

The program throws an error as shown below. I find this error when I use version 4.0.0, as I was able to open excel file using version 3.17 or earlier.

Hope the issue faced is clear & await inputs on how to fix this issue.

Note: Found some related queries but they relate to earlier versions of POI – Link1 Link2

Code:

public static void main(String[] args) {
        try {
            // Open Excel XLSX file
            FileInputStream fis = new FileInputStream(excelFile);
            ZipSecureFile.setMinInflateRatio(0);
            XSSFWorkbook workBook = new XSSFWorkbook(fis);
            System.out.println(workBook);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Gradle:

compile 'org.apache.poi:poi:4.0.0'
compile 'org.apache.poi:poi-ooxml:4.0.0'
//    Tried adding the below jar's as well but dint help
//    compile 'org.apache.commons:commons-collections4:4.2'
//    compile 'org.apache.poi:poi-ooxml-schemas:4.0.0'
//    compile 'org.apache.xmlbeans:xmlbeans:3.0.1'

Error:

org.apache.poi.ooxml.POIXMLException: org/apache/poi/POIXMLTypeLoader
    at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:66)
    at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:648)
    at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:180)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:286)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:307)
    at main.Test.main(Test.java:32)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56)
    at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:63)
    ... 5 more
Caused by: java.lang.NoClassDefFoundError: org/apache/poi/POIXMLTypeLoader
    at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)
    at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:86)
    ... 11 more
Caused by: java.lang.ClassNotFoundException: org.apache.poi.POIXMLTypeLoader
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 13 more

2

Answers


  1. i had the same issue trying to use poi 4.0.1.

    Adding compile "org.apache.poi:ooxml-schemas:1.4" fixed the issue for me

    all my dependencies:

    compile "org.apache.poi:ooxml-schemas:1.4"
    compile "org.apache.poi:poi:4.0.1"
    compile "org.apache.poi:poi-ooxml:4.0.1"
    
    Login or Signup to reply.
  2. Just upgrade your POI version to 4.1.0 or greater.

    In a pom.xml it would be like:

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>4.1.0</version>
    </dependency>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search