Nick
Nick

Reputation: 241

Issues resolving XSSFWorkbook - Java - POI .jar

I'm trying to do work upgrading a Java application to handle .xlsx, using a newer POI library than our existing one. I'm having issues similar to those mentioned in the comments to the answer here: Apache POI, using both XSSF and HSSF

I'm pointing the new ss.usermodel, but it keeps telling me it can't resolve the XSSF workbook declaration:

Workbook xlsImport = new XSSFWorkbook();

I dug through some of their documentation and saw that XSSFWorkbook isn't a part of org.apache.poi.ss.usermodel. It's a part of org.apache.poi.xssf.usermodel.XSSFWorkbook. But there's no poi.xssf for me to import. Am I pointing to the wrong thing? I'm using POI 3.7 Thanks for any help you can provide.

Upvotes: 24

Views: 63950

Answers (6)

Peter Tadros
Peter Tadros

Reputation: 9297

You need to include poi-ooxml jars. You can add it to pom.xml file

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

Upvotes: 17

Tarit Ray
Tarit Ray

Reputation: 994

https://stackoverflow.com/a/65141876/5886712

Earlier It was giving error like below when I was using maven dependency , but after using downloaded binary jar files i.e. : "https://poi.apache.org/download.html" of poi of latest version its working fine for me .

Getting error saying : "IncompatibleClassChangeError: Found interface org.apache.poi.util.POILogger, but class was expected
    at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:303)
    at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:163)
    at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:133)
    at org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:570)
    at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:723)
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:302)
    at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:37)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:307)
    at com.glide.platform_ml.regressionTests.classification.ExcelCallTest.readData(ExcelCallTest.java:40)
    at com.glide.platform_ml.regressionTests.classification.ExcelCallTest.main(ExcelCallTest.java:29)
"

Upvotes: 0

Tarit Ray
Tarit Ray

Reputation: 994

Earlier It was giving error like below when I was using maven dependency , but after using downloaded binary jar files i.e. : "https://poi.apache.org/download.html" of poi of latest version its working fine for me .

Getting error saying : "IncompatibleClassChangeError: Found interface org.apache.poi.util.POILogger, but class was expected
    at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:303)
    at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:163)
    at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:133)
    at org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:570)
    at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:723)
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:302)
    at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:37)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:307)
    at com.glide.platform_ml.regressionTests.classification.ExcelCallTest.readData(ExcelCallTest.java:40)
    at com.glide.platform_ml.regressionTests.classification.ExcelCallTest.main(ExcelCallTest.java:29)
"

Upvotes: 0

Santosh Gdr
Santosh Gdr

Reputation: 65

if you created maven project use below dependency in pom.xml file

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

otherwise import this in your java file

import org.apache.poi.ss.usermodel.Workbook;

Upvotes: 2

The Gav Lad
The Gav Lad

Reputation: 290

First you need to include the proper jar files into your libraries, poi-ooxml-schemas-3.8-20120326.jar. You can find these at http://poi.apache.org/download.html. And you need to add the following link to your java file.

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

Upvotes: 5

Joe Kearney
Joe Kearney

Reputation: 7527

You need to include the poi-ooxml jars to get the XSSF library. The poi jar only has the HSSF libraries.

Upvotes: 38

Related Questions