Recently upgraded POI jar version from 3.17 to 5.1 and below code which was working in 3.x is now broken, ( jdk 1.8 )
Below are the set of Jar used

below is my stub:
import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ReadExcelDemo
{
public static void main(String[] args)
{
try
{
FileInputStream file = new FileInputStream(new File("D:\\TemporaryUploadContainer\\61C50E5C2395C7FB48499BCFDD797F15_QuickCartExample.xlsx"));
//Workbook workbook1 = WorkbookFactory.create(file);
//Sheet sheet1 = workbook1.getSheetAt(0);
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
//Iterate through each rows one by one
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext())
{
Row row = rowIterator.next();
//For each row, iterate through all the columns
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
Cell cell = cellIterator.next();
//Check the cell type and format accordingly
switch (cell.getCellType())
{
case NUMERIC:
System.out.print(cell.getNumericCellValue() + "t");
break;
case STRING:
System.out.print(cell.getStringCellValue() + "t");
break;
}
}
System.out.println("");
}
file.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Below Error for : Workbook workbook1 = WorkbookFactory.create(file);
Exception in thread "main" java.lang.NoSuchFieldError: Factory at org.apache.poi.xssf.model.ThemesTable.(ThemesTable.java:86) at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:61) at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:661) at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:165) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:275) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:296) at test.XLSXReaderWriterP21.readRecordsFromFile(XLSXReaderWriterP21.java:76) at test.XLSXReaderWriterP21.main(XLSXReaderWriterP21.java:57)
Below Error for : XSSFWorkbook workbook = new XSSFWorkbook(file);
Exception in thread "main" java.lang.NoSuchFieldError: Factory at org.apache.poi.xssf.model.ThemesTable.(ThemesTable.java:86) at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:61) at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:661) at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:165) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:275) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:296) at test.ReadExcelDemo.main(ReadExcelDemo.java:26)
I had the same problem. Try to remove poi-ooxml-schemas-4.1.2.jar, and add poi-ooxml-lite-5.2.1.jar
I had the same problem with Netbeans, when i try to use:
XSSFWorkbook workbook = new XSSFWorkbook(fis);
or
Workbook workbook = WorkbookFactory.create(inputFile);
I fixed the problem changing poi-ooxml-schemas-4.1.2.jar for poi-ooxml-lite-5.2.2.jar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With