When I am trying to run my XLUtil class to count the number of rows in the XLSX file I am getting following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
at testXLSReadWrite.XLUtils.getRowCount(XLUtils.java:23)
at testXLSReadWrite.SimpleReadClass.main(SimpleReadClass.java:9)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 2 more
the classes I am using are here under
package testXLSReadWrite;
import java.io.IOException;
public class SimpleReadClass {
static XLUtils xl = new XLUtils();
public static void main(String [] ss) throws IOException {
int row = xl.getRowCount("C:\\Users\\jq2870\\eclipse-workspace\\TestJava Project\\configuration\\UserLoginData.xlsx", "Sheet1");
System.out.print(row);
}
}
And XLUtils class is
public class XLUtils {
public static FileInputStream fi;
public static FileOutputStream fo;
public static XSSFWorkbook wb;
public static XSSFSheet ws;
public static XSSFRow row;
public static XSSFCell cell;
public static int getRowCount(String xlfile,String xlsheet) throws IOException{
fi = new FileInputStream(xlfile);
wb = new XSSFWorkbook(fi);
ws = wb.getSheet(xlsheet);
int rowcount = ws.getLastRowNum();
wb.close();
fi.close();
return rowcount;
}
public static int getCellCount(String xlfile, String xlsheet,int rownum) throws IOException {
fi = new FileInputStream(xlfile);
wb = new XSSFWorkbook(fi);
ws = wb.getSheet(xlsheet);
row = ws.getRow(rownum);
int cellcount = row.getLastCellNum();
wb.close();
fi.close();
return cellcount;
}
public static String getCellData(String xlfile, String xlsheet,int rownum, int colnum) throws IOException
{
fi = new FileInputStream(xlfile);
wb = new XSSFWorkbook(fi);
ws = wb.getSheet(xlsheet);
row = ws.getRow(rownum);
cell = row.getCell(colnum);
String data;
try{
DataFormatter formatter = new DataFormatter();
String cellData = formatter.formatCellValue(cell);
return cellData;
}
catch(Exception e){
data = "";
}
wb.close();
fi.close();
return data;
}
public static void setCellData(String xlfile, String xlsheet,int rownum, int colnum, String data) throws IOException {
fi = new FileInputStream(xlfile);
wb = new XSSFWorkbook(fi);
ws = wb.getSheet(xlsheet);
row = ws.getRow(rownum);
cell = row.createCell(colnum);
cell.setCellValue(data);
fo = new FileOutputStream(xlfile);
wb.write(fo);
wb.close();
fi.close();
fo.close();
}
}
Please can someone tell me why this is happening, every time it's saying that the XSSFWorkbook.class is not found. I am using Eclipse IDE Version: 2020-03 (4.15.0) and Java version Java SE 1.8.0 (JDK 14.0.1)
XL file is having Single row with Username and Password