2

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());
}
Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
saran
  • 23
  • 1
  • 3
  • Don't mix jars between versions! You need to have all your POI jars on the same version for it to work – Gagravarr Jun 27 '17 at 21:25
  • 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 Tikka – saran Jun 28 '17 at 12:33

2 Answers2

0

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.

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
  • i need to parse the file with xlsb format if I use XSSFEventBasedExcelExtractor it will give null for the statement sop(ext.getText()) Even after changing the ext to XSSFBEventBasedExcelExtractor, the error remains the same – saran Jun 27 '17 at 18:29
  • @saran - Check this question -> https://stackoverflow.com/questions/43900342/reading-xlsb-file-with-apache-poi ; OP was able to successfully read data. You should give a try once instead! In case of any further query, feel free to ask. – Am_I_Helpful Jun 27 '17 at 18:34
  • I begin writing using that code snippet for which i received the same error My aim is to read and access the data in the xlsb file which i am trying to do using apache poi 3.16 but unfortunately i am receiving this error – saran Jun 27 '17 at 18:40
  • The issue is resolved when I tried the snippet in a separate java file. Though, I am facing the following error in my project (NoSuchFieldError) java.lang.NoSuchFieldError: RAW_XML_FILE_HEADER Thanks Bro! – saran Jun 27 '17 at 18:51
0

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

saran
  • 23
  • 1
  • 3