0

I am getting the following error when trying to run the code below (involving reading Excel spreadsheet data working in Java), but get the error below...

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

... I was thinking that I should include just include some Log4j2 package, but was told that this is actually an issue with Java and the Workbook class itself. These are the dependencies I have set up in my build.gradle file...

implementation 'org.apache.commons:commons-collections4:4.4'  // https://commons.apache.org/proper/commons-collections/download_collections.cgi
implementation 'org.apache.poi:poi:5.2.3'  // https://mvnrepository.com/artifact/org.apache.poi/poi
implementation 'org.apache.poi:poi-ooxml:5.2.3'  // https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml
implementation 'org.apache.poi:poi-ooxml-schemas:4.1.2'  // https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas
implementation 'org.apache.xmlbeans:xmlbeans:5.1.1'  // https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans

While the code in question is as follows...

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;

@SuppressWarnings("ALL")
public class appium_stuff 
{ 
    @Test
    public void test()  throws IOException 
    {
        FileInputStream fis = new FileInputStream("D:\\[some Windows dir]\\[name of file].xlsx");
        Workbook wb = WorkbookFactory.create(fis);  // <<< error references this line
        Sheet sheet = wb.getSheet("Sheet1");
    }
}
ackmondual
  • 385
  • 3
  • 12
  • Who told you that this was "an issue with Java and the Workbook class itself"? Did they suggest a solution? Have you tried the action that the error message suggests? – tgdavies Mar 22 '23 at 20:40
  • @tgdavies Our IT/IS person. No solution suggested other than it seems something related to Java (which wasn't his area). Tried adding in the LogExample class, and the 2 lines of code from here, but still getting that error... https://stackoverflow.com/questions/47881821/error-statuslogger-log4j2-could-not-find-a-logging-implementation/48566276#48566276 – ackmondual Mar 22 '23 at 21:44

1 Answers1

0

I ended up adding the below to resolve this...

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

... Related to my initial code, I couldn't get that to work on the XSSF format (that uses Excel 2007 or later, or the XLSX extension), so changed it to work with HSSF (that uses Excel 2003 or prior, or the XLS extension) and being sure that my Excel spreadsheets are saved as .XLS (without the 'x' at the end)

ackmondual
  • 385
  • 3
  • 12