我正在使用以下代码读取excell工作表的内容。文件的名称是Test File,工作表的名称是Input。但是它会产生代码下面提到的错误:

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();}
            }

 }


错误是:

 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


请提供应编辑的代码,对我有所帮助。谢谢。我为此使用日食。

最佳答案

下载并实现以下jar文件:

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

10-08 19:32