I am using the following code to read the contents of an excell sheet.The name of the file is Test File and the name of the sheet is Input. but its generating the error mentioned below the code:
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
public class ReadExcel {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
try{ File excel = new File ("D:\\Test file.xlsx");
FileInputStream fis = new FileInputStream(excel);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet ws = wb.getSheet("Input");
int rowNum = ws.getLastRowNum() + 1;
int colNum = ws.getRow(0).getLastCellNum();
String [][] data = new String [rowNum] [colNum];
for(int i = 0; i <rowNum; i++){
XSSFRow row = ws.getRow(i);
for (int j = 0; j < colNum; j++){
XSSFCell cell = row.getCell(j);
String value = cell.toString();
data[i][j] = value;
System.out.println ("the value is " + value);
}
}
}
catch(Exception e){ e.printStackTrace();}
}
}
the error is:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/xmlbeans/XmlException
at ReadExcel.main(ReadExcel.java:29)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
at java.net.URLClassLoader$1.run(URLClassLoader.java:359)
at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
kindly help me by giving the code that should be edited.thanks. i am using eclipse for this.
download and implement following jar files::
poi-3.5-FINAL.jar
poi-3.9-20121203.jar
poi-examples-3.9-20121203.jar
poi-excelant-3.9-20121203.jar
poi-ooxml-3.9-20121203.jar
poi-ooxml-schemas-3.9-20121203.jar
poi-scratchpad-2.5.1-final-20040804.jar
poi-scratchpad-3.9-20121203.jar
xmlbeans-2.3.0.jar