java.lang.ClassNotFoundException : org. apache.xmlbeans.XmlException 异常

标签 java apache-poi

为了读取我正在使用 apache POI 的 xlsx 文件,我下载了 zip 并将以下 jsrs 放在我的 servlet 位置 webcontent/web-inf/lib 并通过 eclipse 配置构建路径

enter image description here

我的代码如下所示,

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;

File uploadedFile = new File(fpath, fileName);
item.write(uploadedFile);
String mimeType = (Files.probeContentType(uploadedFile.toPath())).toString();
System.out.println(mimeType);
if(mimeType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
{
FileInputStream file = new FileInputStream(uploadedFile);
    XSSFWorkbook workbook = new XSSFWorkbook(file);
    for (int i =0; i < workbook.getNumberOfSheets(); i++)
    {
       XSSFSheet sheet = workbook.getSheetAt(i);
       Iterator<Row> row = sheet.iterator();
       while(row.hasNext()) {
   Iterator<Cell> cellIterator = ((Row) row).cellIterator();
       while(cellIterator.hasNext()) {
       Cell cell1 = cellIterator.next();
       switch(cell1.getCellType()) 
         {
    case Cell.CELL_TYPE_BOOLEAN:
    System.out.print(cell1.getBooleanCellValue() + "\n");
    break;
    case Cell.CELL_TYPE_NUMERIC:
    System.out.print(cell1.getNumericCellValue() + "\n");
    break;
    case Cell.CELL_TYPE_STRING:
    System.out.print(cell1.getStringCellValue() + "\n");
    break;
    }
     }

虽然这在 eclipse 上没有显示和错误,但当我尝试运行代码时显示以下错误

enter image description here

我的错误是什么?如何解决?

最佳答案

您需要添加 XML beans依赖于你的类路径。

该库通常称为xmlbeans-x.x.x.jar

关于java.lang.ClassNotFoundException : org. apache.xmlbeans.XmlException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23080945/

相关文章:

java - 如何插入换行符作为单元格的数据?

java - hibernate 使用 apache-poi 在外键字段中插入空值

java - FileNotFoundException 发生在 linux

java - 如何在 JodConverter 中读取 doc 或 pdf 中的文本

java - Android 对话框在一定的计算后关闭

java - 一种反转java String.split()效果的方法?

java - 从未使用过的值/缺少返回语句

java - 在单独的线程中运行逻辑仍然锁定 UI - Java

java - Hazelcast 锁 - 实例死亡

Java 如何使用 JFileChooser 保存由 Apache POI 创建的 excel 文件