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

15 java apache-poi

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

在此输入图像描述

我的代码如下,

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;
    }
     }
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述

我的错是什么?怎么解决这个?

Men*_*ena 37

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

通常会调用该库 xmlbeans-x.x.x.jar

  • 手动:获取 jar,转到项目、属性、Java 构建路径,添加外部 jar 并选择 .jar 文件。 (2认同)

man*_*ear 6

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

附上截图FYR。

xlsx所需的主罐 文件夹ooxml-lib下的xmlbeans-xxxjar


Jay*_*Jay 5

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