javaapache-poiillegalaccessexceptionxlsb

Reading xlsb files throws error - java poi


I'm attempting to use Apache POI and getting the following exception:

Exception in thread "main" java.lang.IllegalAccessError: tried to access field org.apache.poi.xssf.eventusermodel.XSSFReader.pkg from class org.apache.poi.xssf.eventusermodel.XSSFBReader at org.apache.poi.xssf.eventusermodel.XSSFBReader.getXSSFBStylesTable(XSSFBReader.java:78) at org.apache.poi.xssf.extractor.XSSFBEventBasedExcelExtractor.getText(XSSFBEventBasedExcelExtractor.java:122) at xlsbpar.XlsbPar.main(XlsbPar.java:38)

Here's my code:

XSSFBEventBasedExcelExtractor ext = null;
try {
    ext = new XSSFBEventBasedExcelExtractor("C:\\Users\\name\\Desktop\\abc.xlsb");
    System.out.println(ext.getText());
} catch (Exception ex) {
    System.out.println(ex.getMessage());
}

Solution

  • You need to use XSSFEventBasedExcelExtractor (need poi-ooxml-x.y.jar as the external library, where x.y represents the version) as the error itself states:

    tried to access field org.apache.poi.xssf.eventusermodel.XSSFReader.pkg from class org.apache.poi.xssf.eventusermodel.XSSFBReader.

    XSSFEventBasedExcelExtractor ext = null;
    try {
        ext = new XSSFEventBasedExcelExtractor("C:\\Users\\name\\Desktop\\abc.xlsb");
        System.out.println(ext.getText());
    
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
    

    Also, you may like to check this question on reading xlsb file using Apache POI where OP has used almost the similar code with slight addition to achieve the desired result.