通过apche poi读取xlsx文件时出错

时间:2016-01-07 08:50:59

标签: java excel apache jar

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.util.Iterator;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class Exx {

public static void main(String[] args) throws IOException {

    FileInputStream fis = new FileInputStream(new File("D:\\eXCEL.xlsx"));

    //WorkbookFactory wrk1 =  WorkbookFactory.create(fis)

    XSSFWorkbook workbook = new XSSFWorkbook (fis);

    XSSFSheet sheet = workbook.getSheetAt(0);

    Iterator ite = sheet.rowIterator();

    while(ite.hasNext()){

        Row row = (Row) ite.next();

        Iterator<Cell> cite = row.cellIterator();

        while(cite.hasNext()){

            Cell c = cite.next();

            System.out.print(c.toString() +"  ");
        }
        System.out.println();
    }
    fis.close();
  }
} 

这是我的源代码。 使用的JAR文件是

  • POI-3.10-FINAL.jar
  • POI-例子-3.10.jar
  • POI-excelant-3.10.jar
  • POI-OOXML-3.10.jar
  • POI暂存器-3.10-final.jar
  • 的XMLBean-2.3.0.jar
  • dom4j1.6 jar

运行时遇到错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
at Exx.main(Exx.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
  at java.net.URLClassLoader$1.run(Unknown Source)
  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)
... 1 more

请帮忙整理一下。我尝试了所有豆类,但也遇到了错误。

1 个答案:

答案 0 :(得分:0)

如果下面的jar包含在类路径中,代码运行正常:

  • DOM4J-1.6.1.jar
  • POI-3.10-FINAL.jar
  • POI-OOXML-3.10-FINAL.jar
  • poi.ooxml-架构 - 3.10 - FINAL.jar
  • 的xmlbeans-2.3.0.jar