用JAVA从Excel工作表2007读取数据
我在尝试读取 Excel 2007 电子表格 (.xlsx) 时遇到问题。我试图使用 POI 库 在 JAVA 中实现该方法,但出现此错误:
线程“main”中出现异常java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException
这是我的方法:
public void No_rows() throws IOException {
File inputWorkbook = new File(inputFile);
FileInputStream w = new FileInputStream(inputWorkbook);
XSSFWorkbook workbook = new XSSFWorkbook(w);
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator rows = sheet.rowIterator();
int number=sheet.getLastRowNum();
this.num_rows = number;
w.close();
}
I am having a problem when trying to read an Excel 2007 spreadsheet (.xlsx). I am trying to implement the method in JAVA by using the POI library, but I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/xmlbeans/XmlException
and this is my method:
public void No_rows() throws IOException {
File inputWorkbook = new File(inputFile);
FileInputStream w = new FileInputStream(inputWorkbook);
XSSFWorkbook workbook = new XSSFWorkbook(w);
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator rows = sheet.rowIterator();
int number=sheet.getLastRowNum();
this.num_rows = number;
w.close();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是创建并读取 *.xlsx 文件。如果出现该错误,请包含
jaxp--api-1.4.jar
。This is to create and read an *.xlsx file. If you get that error, include the
jaxp--api-1.4.jar
.正如 @Michael-O 在评论中提到的,类路径中缺少 XML Bean。 XMLBeans 库可以在 http://xmlbeans.apache.org/ 找到。
As mentioned by @Michael-O in the comments, XML Beans are missing from the classpath. The XMLBeans library can be found at http://xmlbeans.apache.org/ .
xml bean 库
您必须在构建路径中包含 xmlbeans 库。它通常位于 poi-apache 库的 ooxml-lib 中。
xml bean library
You have to include xmlbeans library in your build path. It is usually in your ooxml-lib in your poi-apache library.