Forum Discussion

mkajale2's avatar
mkajale2
Occasional Contributor
6 years ago

NoClassDefFoundError: while reading XLSX file using XSSF cls for getCellType() /getStringCellValue()

Hello,

I am trying to read data from .XLSX file using Latest Apache POI libraries  4.0.1.  However I amgetting follwoing error when I am trying to getCellType() or cell.getStringCellValue() etc.

However it could read wb.getPhysicalNumberOfRows() , row.getCell(x) properly without error.

error - NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/CTExtensionList

Steps followed - 

 

  1. Download the latest release version of the Apache POI libraries 4.0.1.
  2. Place the extracted libraries (all of the .jar files in the main extraction directory, \lib and ooxml-lib directories) to the ReadyAPI installation directory\bin\ext directory and restart ReadyAPI.
  3. Use this script:

    package application;

    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Iterator;

    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;

    import org.apache.poi.xssf.usermodel.XSSFCell;
    import org.apache.poi.xssf.usermodel.XSSFRow;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    import org.apache.poi.ss.usermodel.DataFormatter;


    InputStream ExcelFileToRead = new FileInputStream("D:\\Test.xlsx");
    XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead);
    XSSFWorkbook test = new XSSFWorkbook();
    XSSFSheet sheet = wb.getSheetAt(0);
    XSSFRow row;
    XSSFCell cell;

    Iterator rows = sheet.rowIterator();
    while (rows.hasNext())
    {
    row=(XSSFRow) rows.next();
    Iterator cells = row.cellIterator();
    while (cells.hasNext())
    {
    cell=(XSSFCell) cells.next();
    if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING)
    {
    System.out.print(cell.getStringCellValue()+" ");
    }
     else if(cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC)
     {
     System.out.print(cell.getNumericCellValue()+" ");
     }
    else
     {
     }
    }
    System.out.println();
    }

Please let me know how to resolve this error.

 

regards,

Manali

 

11 Replies