如何解决错误java.lang.NoClassDefFoundError:org/apache/xmlbeans/XmlObject

如何解决错误java.lang.NoClassDefFoundError:org/apache/xmlbeans/XmlObject,java,xssf,Java,Xssf,这是我的密码。我找不到错误背后的原因。当我使用hssf和.xls文件时效果很好,但我需要使用.xlsx文件,这就是我使用xssf的原因。尝试将此库添加到依赖项中: File file = new File("D:\\testExcelInput.xlsx"); FileInputStream fIP = new FileInputStream(file); //get the existing sheet from the workbook XSSFWorkbook wb

这是我的密码。我找不到错误背后的原因。当我使用hssf和.xls文件时效果很好,但我需要使用.xlsx文件,这就是我使用xssf的原因。

尝试将此库添加到依赖项中:

File file = new File("D:\\testExcelInput.xlsx");
    FileInputStream fIP = new FileInputStream(file);

  //get the existing sheet from the workbook
    XSSFWorkbook wb = new XSSFWorkbook(fIP);
    XSSFSheet sheet = wb.getSheetAt(0);

  //get the count of already existing rows  
    int i=sheet.getPhysicalNumberOfRows();
    Row row=sheet.createRow(++i);

  //input date in the required format  
    Cell cellDate = row.createCell(0);
    cellDate.setCellValue(dateFormat.format(date));

  //input item ID 
    Cell cellItem = row.createCell(1);
    //cellItem.setCellType(CellType.NUMERIC);
    cellItem.setCellType(XSSFCell.CELL_TYPE_NUMERIC);
    cellItem.setCellValue(ItemID);

  //input name
    Cell cellName = row.createCell(2);
    cellName.setCellValue(ItemName);

  //create a number cell and insert quantity 
    Cell cellQuant = row.createCell(3);
    cellQuant.setCellType(XSSFCell.CELL_TYPE_NUMERIC);
    cellQuant.setCellValue(quant);

    try ( //save the changes by writing the data in the workbook
            FileOutputStream fileOut = new FileOutputStream("D:\\testExcelInput.xlsx")) {
        wb.write(fileOut);
        //wb.close();
当您使用
.xlsx
文件时需要它

如果您使用的是maven,则可以通过以下方式创建依赖关系:

xmlbeans-2.6.0.jar

org.apache.xmlbeans
xmlbeans
2.6.0
<dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>2.6.0</version>
</dependency>