10

I'm using apache POI for reading xlsx files by adding below dependencies

<dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.8</version>
        </dependency>

<dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.5.0</version>
        </dependency>

I'm getting following exception while running with jetty plugin even if deployed in tomcat.

org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
    at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
    at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)
    at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
......

Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
...........
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument
    at org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument$Factory.parse(Unknown Source)
    at org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:121)
    at org.apache.poi.xssf.model.StylesTable.<init>(StylesTable.java:92)
    ... 186 more

I removed the xmlbeans dependency as the maven will automatically download poi dependencies , still the same exception.Any help?

pavan
  • 3,225
  • 3
  • 25
  • 29

5 Answers5

15

I used poi with version 3.12. The following dependency is also required:

compile 'org.apache.poi:ooxml-schemas:1.1'

see also http://poi.apache.org/faq.html#faq-N10025

  • From the link: There are two jar files available. The full jar of all of the schemas is ooxml-schemas-1.x.jar and smaller poi-ooxml-schemas jar is only about 4mb. This latter jar file only contains the typically used parts though. – mzzzzb Apr 06 '16 at 13:43
  • latest version: http://search.maven.org/#artifactdetails%7Corg.apache.poi%7Cooxml-schemas%7C1.3%7Cjar – slim Dec 07 '16 at 20:26
4

I have made it run for these dependencies:


     def poiVersion='3.9'
     compile 'org.apache.poi:poi:'+poiVersion
     compile 'org.apache.poi:poi-ooxml:'+poiVersion
     compile 'org.apache.poi:poi-ooxml-schemas:'+poiVersion

When I try for others it does not work:

3.10 : is not known to maven central

3.11 : fails, with exact the error in this case !!!

Conclusion POI 3.9 works !!!!

anders
  • 175
  • 2
  • 7
  • 2
    I am failing with the same errors, and have the same experience when adjusting versions, except that my "`ClassNotFound`" is `org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExtensionList`. Does anyone know if this is reported as a bug in `poi-ooxml` 3.11? – BalRog Mar 19 '15 at 15:34
  • this answer is misleading its not that poi 3.12 is broken, you need to include full ooxml-schemas dependency. Note there are two similarly named jars. see Aliaksandr Pyrkh's answer below. – mzzzzb Apr 06 '16 at 13:39
4

I tried using poi 3.10, 3.11 and 3.12 beta with Grails and get this error as well.

After downloading and including http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/poi/ooxml-schemas/1.0/ooxml-schemas-1.0.jar the error is gone.

A.W.
  • 2,858
  • 10
  • 57
  • 90
0

I use 3.7 but have you try adding

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>3.8</version>
    </dependency>
Bruno Grieder
  • 28,128
  • 8
  • 69
  • 101
  • Getting the same exception even after adding this dependency, even i tried 3.7 version but in vain. – pavan Apr 26 '12 at 12:07
  • For 3.7, I have it working with poi-3.7, poi-ooxml-3.7, poi-ooxml-schemas-3.7, xmlbeans-2.3.0, geronimo_stax_api_1.0 and dom4j-1.6.1 – Bruno Grieder Apr 26 '12 at 12:37
  • Even after adding all the dependencies you mentioned same exception. – pavan Apr 26 '12 at 14:12
  • I am having this exact problem. I've added all these libraries to my filepath. I'm using this with oracle's OAS. – berto77 Oct 15 '12 at 21:13
0

This is happening due to inconsistency is the poi jars. You can download latest jars and it will start working.

you can add latest jar files for all below:

Commons-compress , ooxml-schemas , poi-scratchpad , poi-ooxml , poi , poi-ooxml-schemas , dom4j , poi-excelant