2

Let me start by saying that I have seen a lot of questions regarding the error XSSFWorkbook cannot be resolved to a type. However, I have looked into most of them, and the accepted answer seems to be to add the Maven dependency poi-ooxml. Indeed, this is supported by the information on the Apache POI official site.

However, this is still not working for me. All the answers that I have seen so far used quite older versions. I fear that the answer might be different for the current ones.

Another interesting thing is that I was using the jar manually before, and I didn't experience any issues. However, when trying to import it as a Maven dependency, org.apache.poi.xssf.usermodel.XSSFWorkbook seems to be the only import that it's missing.

Ps: I've also tried to use poi-ooxml-full and poi-ooxml-schemas, but none of it worked.

pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>s6-night-shift</groupId>
  <artifactId>s6-night-shift</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <release>15</release>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>com.sun.activation</groupId>
        <artifactId>javax.activation</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>com.j2html</groupId>
        <artifactId>j2html</artifactId>
        <version>1.5.0</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.5.0-b01</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>5.2.0</version>
        <type>pom.sha512</type>
    </dependency>
  </dependencies>
</project>
Jak
  • 178
  • 10
  • 3
    could you try removing `pom.sha512` ? this will get you a pm.sha512 file instead of a jar – PJ Fanning Jan 20 '22 at 15:13
  • @PJFanning Ohh, wow, it worked! Any idea on why using Maven through Eclipse would add that line by default? Any chance I can disable it for future uses? Ps: Also, if you'd be so kind as to put that in an answer so that I can accept it ;) – Jak Jan 20 '22 at 15:16
  • 2
    absolutely no idea - always a good idea to read the code that IDEs generate to check that nothing weird was added – PJ Fanning Jan 20 '22 at 15:17

1 Answers1

0

You need to add another Apache dependency in your pom.xml file. Prefarably something like this below. This is so because both depencies are needed for Apache POi XSSFWorkbook class to be resolved.

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>5.2.0</version>
    </dependency>