2015-11-06 52 views
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(""); 
     } 
+0

你得到什么错误? –

+0

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) –

+0

由于jar中的版本不匹配,它看起来像是一个错误。尝试使用不同版本的jar进行xlsx阅读。 –

回答

0

我得到了答案。为此,我们需要导入dom4j jar和poi ooxml模式也。我忘了这两个文件