gpt4 book ai didi

Java 程序从 Excel 文件读取数据抛出错误..需要帮助解决

转载 作者:行者123 更新时间:2023-12-01 13:46:46 24 4
gpt4 key购买 nike

我正在使用 XSSF 用户模型读取 Excel 文件中的数据并打印它们。我已将所有 POI Jar 文件添加到 Java 构建路径 --> 库中。但我仍然遇到同样的错误。请帮我解决这个问题。包 com.javalab.sample;

import java.io.*;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class ReadFromExcel3 {

public static void main(String[] args) {
try {

File excel1 = new File ("C:\\TestData\\test.xlsx");
FileInputStream fis1 = new FileInputStream(excel1);

XSSFWorkbook xssfWork = new XSSFWorkbook(fis1);
XSSFSheet sheet1 = xssfWork.getSheetAt(0);
Iterator<Row> rowItr = sheet1.rowIterator();

while ( rowItr.hasNext() )
{
XSSFRow row = (XSSFRow) rowItr.next();
System.out.println("ROW:-->");
Iterator<Cell> cellItr = row.cellIterator();

while ( cellItr.hasNext() )
{
XSSFCell cell = (XSSFCell) cellItr.next();
System.out.println("CELL:-->"+cell.toString());
}
}
}

catch (Exception e)
{
e.printStackTrace();
}

}
}
<小时/>

异常

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/xmlbeans/XmlException
at com.javalab.sample.ReadFromExcel3.main(ReadFromExcel3.java:22)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
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

最佳答案

您忘记在类路径中添加 POI 二进制发行版(在 ooxml-lib 下)附带的 xmlbeans-xxx.jar。

关于Java 程序从 Excel 文件读取数据抛出错误..需要帮助解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20310152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com