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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23080945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 20:32:23  来源:igfitidea点击:

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

javaapache-poi

提问by

In order to read an xlsxfile I'm using apache POI, I've downloaded the zip and placed the following jsrs in my servlet location webcontent/web-inf/liband configured build path through eclipse

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

enter image description here

在此处输入图片说明

and my code looks as follows,

我的代码如下所示,

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

Though this does not show and errors on eclipse it shows the following errors when I try to run the code

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

enter image description here

在此处输入图片说明

What is my mistake? How to solve this?

我的错误是什么?如何解决这个问题?

采纳答案by Mena

You need to add the XML beansdependency to your class path.

您需要将XML bean依赖项添加到您的类路径中。

The library is usually called xmlbeans-x.x.x.jar

图书馆通常被称为 xmlbeans-x.x.x.jar

回答by Jay

Add xmlbeans-xpath.jar to your libraries.

将 xmlbeans-xpath.jar 添加到您的库中。

回答by mannedear

I have downloaded the latest poi-3.17 binaries and xmlbeans-x.x.x.jar is included in the downloaded package itself.

我已经下载了最新的 poi-3.17 二进制文件,并且 xmlbeans-xxxjar 包含在下载的包本身中。

Attached the screenshots FYR.

附上截图 FYR。

Primary jars required for xlsxxmlbeans-x.x.x.jar under the folder ooxml-lib

xlsx 所需的主要 jarooxml-lib 文件夹下的 xmlbeans-xxxjar

回答by Gregor Petrin

It looks as though you might be trying to produce Office's 2007 format with the POI version for the old formats. Use the poi-ooxmljar for the new formats.

看起来您可能正在尝试使用旧格式的 POI 版本生成 Office 2007 格式。将poi-ooxmljar 用于新格式。