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.XSSFWorkbo
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<Row> 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<Cell> 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();
}
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'
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
After trying multiple things,what really worked was: 1. downloading "poi" and "poi-ooxml" manually 2.Adding these d/w jars into "Maven Dependencies"
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)
I needed the following files for my implementation:
(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.