Mahmoud Saleh
Mahmoud Saleh

Reputation: 33625

Required maven dependencies for Apache POI to work

I want to use Apache POI library to parse excel files (old versions and newer versions of excel). So I was wondering what jars do i need to include from the Apache POI because in following link:

http://mvnrepository.com/artifact/org.apache.poi

I found lots of jars to be included, do I need to include them all?

If so, what is the latest stable version to be included, and does it work with Microsoft's Office 2010?

Upvotes: 37

Views: 206892

Answers (15)

ChoKaPeek
ChoKaPeek

Reputation: 161

Since POI 5.0.0, some housekeeping has been done:

According to the official FAQ:

  • poi-ooxml-full was previously known as ooxml-schemas
  • poi-ooxml-lite was previously known as poi-ooxml-schemas

According to the official components list:

  • poi-ooxml now transparently requires poi-ooxml-lite

As @mustafa918 noticed, you should refer to https://poi.apache.org/components/index.html#components to find out which dependency you need. To work with XLS, poi will be enough; for XLSX you will need to add poi-ooxml

Upvotes: 0

Md. Nowshad Hasan
Md. Nowshad Hasan

Reputation: 626

Apache POI has mainly two libraries,

  1. To process Excel '97-2007 file format (.xls), called HSSF workbook.
  2. To process Excel 2007 OOXML (.xlsx), called XSSF workbook.

You can add anyone depend on your need. Difference can be found here.

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>5.2.2</version>
</dependency>

Upvotes: 2

Vaibhav Nalawade
Vaibhav Nalawade

Reputation: 11

<?xml version="1.0" encoding="UTF-8"?>

4.0.0 org.springframework.boot spring-boot-starter-parent 2.5.5 com.dolphin excel 0.0.1-SNAPSHOT excel Excel Sheet Import Into Databse Using SpringBoot And Apache Worbook <java.version>1.8</java.version> org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-web

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi</artifactId>
          <version>3.10-FINAL</version>
       </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

The Main Code For Apache POI Then Update Update Maven Project

<dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi</artifactId>
          <version>3.10-FINAL</version>
</dependency>

This Will Work

Upvotes: 0

Neph
Neph

Reputation: 2001

To read an Excel file with Apache POI 5.0.0 like this:

Workbook wb = WorkbookFactory.create(myFile);

... the following libraries are required (latest versions as I'm typing this):

  • commons-collections4-4.4.jar (link)
  • commons-compress-1.20.jar (link)
  • log4j-api-2.14.1.jar (link)
  • log4j-core-2.14.1.jar (downloaded with ^)
  • poi-5.0.0.jar (link)
  • poi-ooxml-5.0.0.jar (downloaded with ^)
  • poi-ooxml-lite-5.0.0.jar / poi-ooxml-full-5.0.0.jar (use only one, downloaded with ^)
  • xmlbeans-5.0.0.jar (link)

If myFile is a ".xls" file, one more library has to be added:

  • commons-math3-3.6.1.jar (link)

Upvotes: 0

code_lantern
code_lantern

Reputation: 64

Add these dependencies to your maven pom.xml . It will take care of all of the imports including OPCpackage

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

Upvotes: -2

Sri Sankaran
Sri Sankaran

Reputation: 8320

No, you don't have to include all of POI's dependencies. Maven's transitive dependency mechanism will take care of that. As noted you just have to express a dependency on the appropriate POI artifact. For example:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.8-beta4</version>
</dependency>

Edit(UPDATE): I don't know about previous versions but to resolve imports to XSSFWorkbook and other classes in org.apache.poi package you need to add dependency for poi-ooxml too. The dependencies will be:

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

Upvotes: 66

Anshul Vij
Anshul Vij

Reputation: 19

There are multiple jars which are required for your APACHE POI to work with your application.

List of JAR file:-

  1. poi-4.1.0
  2. poi-ooxml-4.1.0
  3. commons-collections4-4.3
  4. commons-compress-1.18
  5. xmlbeans-3.1.0
  6. poi-ooxml-schemas-3.9
  7. dom4j-1.6.1

Upvotes: 1

Ripon Al Wasim
Ripon Al Wasim

Reputation: 37816

The following works for me:

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.16</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.16</version>
    </dependency>

Upvotes: 3

mustafa918
mustafa918

Reputation: 518

this is the list of maven artifact id for all poi component. in this link http://poi.apache.org/overview.html#components

Upvotes: 3

Tanmay Vaishya
Tanmay Vaishya

Reputation: 63

Add this dependency to work with Apache POI

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.16-beta1</version>
 </dependency>

Upvotes: 0

Green Lei
Green Lei

Reputation: 3422

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.10-FINAL</version>
    </dependency>

Upvotes: 2

Muthu
Muthu

Reputation: 21

I used the below dependency. If you are using Selenium then it's good to use all of them as below. Else you will see some errors and then do the reserch and add some more dependencies.

<dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>poi</artifactId>
                 <version>3.9</version>
          </dependency>
          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>poi-ooxml</artifactId>
                 <version>3.9</version>
          </dependency>
          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>poi-ooxml-schemas</artifactId>
                 <version>3.9</version>
          </dependency>
          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>poi-scratchpad</artifactId>
                 <version>3.9</version>
          </dependency>
          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>ooxml-schemas</artifactId>
                 <version>1.1</version>
          </dependency>

          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>openxml4j</artifactId>
                 <version>1.0-beta</version>
          </dependency>

Upvotes: 2

Mahmoud
Mahmoud

Reputation: 21

If you are not using maven, then you will need **

  • poi
  • poi-ooxml
  • xmlbeans
  • dom4j
  • poi-ooxml-schemas
  • stax-api
  • ooxml-schemas

Upvotes: 0

Kishor Gaur
Kishor Gaur

Reputation: 43

ooxml for dealing the .xlsx files and the ooxml refers to the xml, hence we will be needed to refer the below three dependedncies in the pom.xml for the

<dependency>
   <groupId>org.apache.poi</groupId>
   <artifactId>poi</artifactId>
   <version>3.9</version>
</dependency>
<dependency>
   <groupId>xml-apis</groupId>
   <artifactId>xml-apis</artifactId>
   <version>1.4.01</version>
</dependency>
<dependency>
   <groupId>org.apache.poi</groupId>
   <artifactId>poi-ooxml</artifactId>
   <version>3.9</version>
   <exclusions>
     <exclusion>
       <artifactId>xml-apis</artifactId>
       <groupId>xml-apis</groupId>
     </exclusion>       
   </exclusions>
</dependency>

Upvotes: -2

Laura Liparulo
Laura Liparulo

Reputation: 2907

For an excel writer you might need the following:

            <dependency>
              <groupId>org.apache.poi</groupId>
              <artifactId>poi</artifactId>
              <version>3.10-FINAL</version>
           </dependency>


        <dependency>
             <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>${apache.poi.version}</version>
       </dependency>

Upvotes: 9

Related Questions