Cannot import XSSF in Apache POI

JavaApache Poi

Java Problem Overview


I am referencing the version 3.7 of the Apache POI and I am getting a "cannot be resolved" error when I do:

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

Other import statements that reference POI DO NOT give me errors, such as:

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

Any ideas??

Java Solutions


Solution 1 - Java

For OOXML to work you need the POI-OOXML jar which is separately packaged from the POI jar.

Download the POI-OOXML jar from the following location -

http://repo1.maven.org/maven2/org/apache/poi/poi-ooxml/3.11/poi-ooxml-3.11.jar

For Maven2 add the below dependency -

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

Solution 2 - Java

The classes for the OOXML file formats (such as XSSF for .xlsx) are in a different Jar file. You need to include the poi-ooxml jar in your project, along with the dependencies for it

You can get a list of all the components and their dependencies on the POI website here.

What you probably want to do is download the 3.11 binary package, grab the poi-ooxml jar from it, and the dependencies in the ooxml-lib directory. Import these into your project and you'll be sorted.

Alternately, if you use Maven, you can see here for the list of the artificats you'll want to depend on, but it'd want to be something like:

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

The poi-ooxml maven dependency will pull in the main POI jar and the dependencies for you automatically. If you want to work with the non-spreadsheet formats, you'd also want to depend on the poi-scratchpad artifact too, as detailed on the POI components page

Solution 3 - Java

I added below contents in app "build.gradle"

implementation 'org.apache.poi:poi:4.0.0'
implementation 'org.apache.poi:poi-ooxml:4.0.0'

Solution 4 - Java

If you use Maven:

poi => poi-ooxml in artifactId

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

Solution 5 - Java

Problem: While importing the " org.apache.poi.xssf.usermodel.XSSFWorkbook"class showing an error in eclipse.

Solution: Use This maven dependency to resolve this problem:

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

-Hari Krishna Neela

Solution 6 - Java

I Got the Solution Guys

You need to keep some points in your mind .

  1. There are two different dependency one is (poi) & other dependency is (poi- ooxml) but make sure you must use poi-ooxml dependency in your code.

  2. Just Add the following dependency in pom.xml & Save it.

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

3 .After you have saved the pom.xml then you need to try a small thing ,Use (.) operator will try to import/fetch it & finally will not see any sort of error because now it has imported that thing in your package.

Sample Code to Understand Better !!

package ReadFile;// package   
import org.apache.poi.xssf.usermodel.XSSFWorkbook;  // automatically added to your code after importing
public class Test          
{  
public static void Hello() // Method  
{  
XSSFWorkbook workbook = new XSSFWorkbook();   
}  
}

I tried my best to give you the solution , If you face any issue comment here i will try
to solve it .

Keep Learning Guys !!

Solution 7 - Java

  1. imported all the JARS from POI folder

  2. Imported all the JARS from ooxml folder which a subdirectory of POI folder

  3. Imported all the JARS from lib folder which is a subdirectory of POI folder

    String fileName = "C:/File raw.xlsx"; File file = new File(fileName); FileInputStream fileInputStream; Workbook workbook = null; Sheet sheet; Iterator rowIterator; try { fileInputStream = new FileInputStream(file); String fileExtension = fileName.substring(fileName.indexOf(".")); System.out.println(fileExtension); if(fileExtension.equals(".xls")){ workbook = new HSSFWorkbook(new POIFSFileSystem(fileInputStream)); } else if(fileExtension.equals(".xlsx")){ workbook = new XSSFWorkbook(fileInputStream); } else { System.out.println("Wrong File Type"); } FormulaEvaluator evaluator workbook.getCreationHelper().createFormulaEvaluator(); sheet = workbook.getSheetAt(0); rowIterator = sheet.iterator(); while(rowIterator.hasNext()){ Row row = rowIterator.next(); Iterator cellIterator = row.cellIterator(); while (cellIterator.hasNext()){ Cell cell = cellIterator.next(); //Check the cell type after evaluating formulae //If it is formula cell, it will be evaluated otherwise no change will happen switch (evaluator.evaluateInCell(cell).getCellType()){ case Cell.CELL_TYPE_NUMERIC: System.out.print(cell.getNumericCellValue() + " "); break; case Cell.CELL_TYPE_STRING: System.out.print(cell.getStringCellValue() + " "); break; case Cell.CELL_TYPE_FORMULA: Not again break; case Cell.CELL_TYPE_BLANK: break; } } System.out.println("\n"); } //System.out.println(sheet); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); }​

Solution 8 - Java

I had the same problem, so I dug through the poi-3.17.jar file and there was no xssf package inside.

I then went through the other files and found xssf int the poi-ooxml-3.17.jar

So it seems the solutions is to add

poi-ooxml-3.17.jar

to your project, as that seems to make it work (for me at least)

Solution 9 - Java

After trying multiple things,what really worked was:

  1. downloading "poi" and "poi-ooxml" manually 2.Adding these d/w jars into "Maven Dependencies"

Solution 10 - Java

Actual for 06.11.2021 days:

<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi</artifactId>
	<version>5.1.0</version>
</dependency>

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

Solution 11 - Java

You did not described the environment, anyway, you should download apache poi libraries. If you are using eclipse , right click on your root project , so properties and in java build path add external jar and import in your project those libraries :

xmlbeans-2.6.0 ; poi-ooxml-schemas- ... ; poi-ooxml- ... ; poi- .... ;

Solution 12 - Java

I needed the following files for my implementation:

  • poi-ooxml-schemas-3.14.20160307.jar
  • commons-codec-1.10.jar (this was in "lib" folder of the zip file you get from apache)
  • curvesapi-1.03.jar (in "ooxml-lib" folder)
  • poi-3.14-20160307.jar
  • poi-ooxml-3.14-20160307.jar
  • xmlbeans-2.6.0.jar (in "ooxml-lib" folder)

(though honestly, I'm not completely sure they are all necessary...) It's a little confusing because they are packaged that way. I needed to place them manually in my own "lib" folder and then add the references...

Maven always seems to download more than I need, so I always place libaries/dlls and things like that manually.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMark JacksonView Question on Stackoverflow
Solution 1 - JavaPushkarView Answer on Stackoverflow
Solution 2 - JavaGagravarrView Answer on Stackoverflow
Solution 3 - JavaDang Thach HaiView Answer on Stackoverflow
Solution 4 - JavaStéphane GRILLONView Answer on Stackoverflow
Solution 5 - JavaHari Krishna NeelaView Answer on Stackoverflow
Solution 6 - JavaSiddharth MittalView Answer on Stackoverflow
Solution 7 - JavaAman KhatriView Answer on Stackoverflow
Solution 8 - JavaMr RedstonerView Answer on Stackoverflow
Solution 9 - JavaSanchi TyagiView Answer on Stackoverflow
Solution 10 - JavaЮрий ГлушкоView Answer on Stackoverflow
Solution 11 - JavafrankView Answer on Stackoverflow
Solution 12 - JavapcalkinsView Answer on Stackoverflow