I am reading a simple Excel File, the code presumably has no errors in Main.java, I have added the following dependencies in the pom.xml file. I have seen the same problem everywhere, some still are old and unsolved, and most of the solution are deprecated. What should I do now? Any help is appreciated.
This is the Main.java
package com.egi.ExcelReader;
import java.io.*;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Main {
public static void readXLSXFile() throws IOException {
InputStream ip = new FileInputStream("C:\\Users\\emjueke\\OneDrive - Ericsson\\Documents\\xlreader\\Test.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(ip);
XSSFSheet sheet = wb.getSheetAt(0);
XSSFRow row;
XSSFCell cell;
Iterator<Row> rows = sheet.rowIterator();
while(rows.hasNext()) {
row = (XSSFRow) rows.next();
Iterator<Cell> cells = row.cellIterator();
while(cells.hasNext()) {
cell = (XSSFCell) cells.next();
switch (cell.getCellType()) {
case STRING -> System.out.print(cell.getStringCellValue() + "\t");
case NUMERIC -> System.out.print(cell.getNumericCellValue() + "\t");
case BOOLEAN -> System.out.print(cell.getBooleanCellValue() + "\t");
}
}
System.out.println();
}
}
public static void main(String[] args) throws IOException {
readXLSXFile();
}
}
These are the dependencies in pom.xml. Haven't used a plugin yet.
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.8.2</version>
</dependency>
</dependencies>
This is the error. Output
I'm using IntelliJ 2022.3.2 CE, JDK19, Apache POI 5.2.3 and Maven 4.0.0