我使用以下代码来读取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
通过提供应该编辑的代码来帮助我。谢谢。我正在使用eclipse。
答案 0 :(得分:1)
下载并实现以下jar文件::
POI-3.5 FINAL.jar
POI-3.9-20121203.jar
POI-例子-3.9-20121203.jar
POI-excelant-3.9-20121203.jar
POI-OOXML-3.9-20121203.jar
POI-OOXML-架构 - 3.9-20121203.jar
POI暂存器-2.5.1-最终20040804.jar
POI暂存器-3.9-20121203.jar
的xmlbeans-2.3.0.jar