35

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?

Robin
  • 8,162
  • 7
  • 56
  • 101
Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498

15 Answers15

64

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>
Prashant Prakash
  • 105
  • 1
  • 10
Sri Sankaran
  • 8,120
  • 4
  • 38
  • 47
  • 1
    This won't resolve `org.apache.poi.xssf.eventusermodel.XSSFReader, org.apache.poi.xssf.model.SharedStringsTable, org.apache.poi.openxml4j.opc.OPCPackage` imports. – Muhammad Gelbana Sep 25 '18 at 14:23
  • @MuhammadGelbana I'm sorry. I've been far removed from this space for several years now. Please update the answer with the required edits. – Sri Sankaran Oct 17 '18 at 19:21
9

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>
Laura Liparulo
  • 2,849
  • 26
  • 27
3

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

mustafa918
  • 498
  • 1
  • 6
  • 15
3

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>
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
2

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>
Muthu
  • 21
  • 1
  • 3
    Apache POI 3.9 is rather old, why are you suggesting people use that? And the `openxml4j` dependency shouldn't be needed these days – Gagravarr Dec 02 '14 at 10:59
  • can't make maven in eclipse recognize any version superior that 3.9. usually it get the job done. Also it's ridiculous to add 6-7 dependencies for something that was supposed to resolve all the dependencies for a library – Leo Jan 29 '18 at 18:24
2
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.10-FINAL</version>
    </dependency>
Green Lei
  • 3,150
  • 2
  • 20
  • 25
1

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
Anshul Vij
  • 19
  • 1
1

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>
0

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

  • poi
  • poi-ooxml
  • xmlbeans
  • dom4j
  • poi-ooxml-schemas
  • stax-api
  • ooxml-schemas
Mahmoud
  • 29
  • 1
  • 5
  • 1
    The stax-api jar and dom4j jar are not needed on the latest release of Apache POI (3.11), so this is not always correct – Gagravarr Sep 17 '14 at 17:56
0

Add this dependency to work with Apache POI

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

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)
Neph
  • 1,823
  • 2
  • 31
  • 69
0
<?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

0

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

ChoKaPeek
  • 151
  • 9
-2

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>
Gagravarr
  • 47,320
  • 10
  • 111
  • 156
-2

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>
Srayan Ray
  • 54
  • 7