2
votes

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());
}
2
Don't mix jars between versions! You need to have all your POI jars on the same version for it to workGagravarr
Exactly! I excluded the previous version of apache poi but i forgot remove the apache tika library which I was not using at all. The problem resolved immediately after removing the reference of Apache Tikkasaran

2 Answers

0
votes

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.

0
votes

The code snippet in the following works perfectly for the XLSB parsing Reading XLSB file with Apache POI which @AM_I_Helpful was suggesting