0

I am using Apache POI to read Excel. I add poi-ooxml to read Excel from resource.

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml-full</artifactId>
    <version>5.2.3</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>5.2.3</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.2.3</version>
</dependency>

And here is my code:

try (InputStream inputStream = this.getClass().getResourceAsStream("/test.xlsx")) {
    workbook = new XSSFWorkbook(inputStream);
} catch (IOException e) {
}

It throws exception with

Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument

I tried to add poi-ooxml-lite but it throws a similar exception about missing DocumentFactory. Please help me correct if I got anything wrong.

f_puras
  • 2,521
  • 4
  • 33
  • 38
  • @trashgod could you specify poi-ooxml plus? I have already used poi-ooxml-full – Mingjia Liu May 10 '23 at 12:25
  • To clarify: as noted in the overview cited [here](https://stackoverflow.com/a/72839258/230513), use `poi-ooxml` with _either_ `poi-ooxml-lite` _or_ `poi-ooxml-full`, _not both_; as an aside, your exception handler appears to be empty. – trashgod May 10 '23 at 16:24
  • @trashgod I didn't use both poi-ooxml-lite and poi-ooxml-full, I tried it separately. But the exception is same. I remove the exception handler part code since it is not related to this issue. – Mingjia Liu May 11 '23 at 08:00
  • I tried reading from a resource stream, but I can't reproduce the effect you describe. – trashgod May 11 '23 at 17:42

0 Answers0