1
但是我收到錯誤。它有沒有任何錯誤。 File myFile = new File(「D:/ abhilash/L2t Tracker.xlsx」); FileInputStream fis = new FileInputStream(myFile);我需要閱讀java中的xlsx文件
// Finds the workbook instance for XLSX file
XSSFWorkbook myWorkBook = new XSSFWorkbook (fis);
// Return first sheet from the XLSX workbook
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
// Get iterator to all the rows in current sheet
Iterator<Row> rowIterator = mySheet.iterator();
// Traversing over each row of XLSX file
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
// For each row, iterate through each columns
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "\t");
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t");
break;
case Cell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue() + "\t");
break;
default :
}
}
System.out.println("");
}
你得到什麼錯誤? –
Ex n線程「main」java.lang.NoClassDefFoundError:org/apache/xmlbeans/XmlObject at L2t.main(L2t.java:30) 導致:java.lang.ClassNotFoundException:org.apache.xmlbeans.XmlObject at java.net.URLClassLoader $ 1.run(URLClassLoader.java:366) at java.net.URLClassLoader $ 1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net .URLClassLoader.findClass(URLClassLoader.java:354) 在java.lang.ClassLoader.loadClass(ClassLoader.java:425) 在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308) 在java.lang中.ClassLoader.loadClass(ClassLoader.java:358) –
由於jar中的版本不匹配,它看起來像是一個錯誤。嘗試使用不同版本的jar進行xlsx閱讀。 –