0
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();

This is my code. I can't find the reason behind the error . it worked fine when i used hssf and .xls file but i needed to use .xlsx file that's why i used xssf .

Mohit Joshi
  • 53
  • 3
  • 9

1 Answers1

0

Try to add this library to your dependencies:

xmlbeans-2.6.0.jar

It's needed when you work with .xlsx files.

If you are using maven you can the dependency this way:

<dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>2.6.0</version>
</dependency>
Nurjan
  • 5,889
  • 5
  • 34
  • 54