Note that there are some explanatory texts on larger screens.

plurals
  1. PORead from excel file .xlsx using java Apache POI 3.9 Eclipse
    text
    copied!<p>I am trying to read a file from a <code>.xlsx</code> file using java. But I still get errors. I already corrected the <code>HSSF</code> to <code>XSSF</code> so it is able to read past 2007 version of excel. The code crashes when instantiating the workbook. Here is the code:</p> <pre><code>package excelread; 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; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ReadExcel { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File excel = new File ("C:/Users/Leah-Dina/Desktop/LogFile.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 &lt;rowNum; i++){ XSSFRow row = ws.getRow(i); for (int j = 0; j &lt; colNum; j++){ XSSFCell cell = row.getCell(j); String value = cell.toString(); data[i][j] = value; System.out.println ("the value is " + value); } } } } </code></pre> <p>Here you can see the error message I get: Seems like everything is imported and I have no idea whats wrong.</p> <pre><code> Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:154) at org.apache.poi.openxml4j.opc.OPCPackage.&lt;init&gt;(OPCPackage.java:141) at org.apache.poi.openxml4j.opc.Package.&lt;init&gt;(Package.java:54) at org.apache.poi.openxml4j.opc.ZipPackage.&lt;init&gt;(ZipPackage.java:82) at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:267) at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39) at org.apache.poi.xssf.usermodel.XSSFWorkbook.&lt;init&gt;(XSSFWorkbook.java:204) at excelread.ReadExcel.main(ReadExcel.java:21) Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 8 more </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload