读取xlsb文件会引发错误 - java poi

时间:2017-06-27 18:14:25

标签: java apache-poi illegalaccessexception xlsb

我试图使用Apache POI并获得以下异常:

  

线程中的异常" main" java.lang.IllegalAccessError:尝试从类org.apache.poi.xssf.eventusermodel.XSSFBReader访问字段org.apache.poi.xssf.eventusermodel.XSSFReader.pkg       在org.apache.poi.xssf.eventusermodel.XSSFBReader.getXSSFBStylesTable(XSSFBReader.java:78)       在org.apache.poi.xssf.extractor.XSSFBEventBasedExcelExtractor.getText(XSSFBEventBasedExcelExtractor.java:122)       在xlsbpar.XlsbPar.main(XlsbPar.java:38)

这是我的代码:

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 个答案:

答案 0 :(得分:0)

您需要使用XSSFEventBasedExcelExtractor(需要poi-ooxml-x.y.jar作为外部库,其中x.y代表版本),因为错误本身表明:

  

试图访问字段org.apache.poi.xssf.eventusermodel.XSSFReader.pkg   来自 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());
}

此外,您可能需要检查this question on reading xlsb file using Apache POI哪个OP使用了几乎相似的代码并略微添加以获得所需的结果。

答案 1 :(得分:0)

以下代码片段非常适合XLSB解析 Reading XLSB file with Apache POI 哪个@AM_I_Helpful建议