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");
}
}
I ended up adding the below to resolve this...
... 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)