Apache POI – Getting Started

Apache POI (Poor Obfuscation Implementation) is an open-source Java API library for manipulating the various Microsoft files format such as Excel, PowerPoint, Word in Java. This article shows you how to set up the environment to build a POI application for manipulating the Microsoft Excel file (XLS and XLSX) format.

Apache POI – Overview

Apache POI is an API provided by Apache Software Foundation for manipulating various file formats based upon Microsoft’s OLE2 Compound Document Format (OLE2) and Office Open XML standards (OOXML). Click here to know more about Apache POI.

Apache POI – Supported Java Version

  • Apache POI 4.0 and later require JDK version 1.8 or later.
  • Apache POI 3.11 and later 3.x versions require JDK version 1.6 or later.
  • Apache POI 3.5 to 3.10 required the JDK version 1.5 or later.
  • Apache POI versions prior to 3.5 required JDK 1.4+.

In this article we are going to use Apache poi-4.0.1 version so it required JDK 1.8+

Apache POI – How to Install?

There are two ways for installing Apache POI in Eclipse based on your project type:

  1. Maven Project
  2. Stand alone Java Project

1. Maven Project

If you are going to create a maven project then you have to add the following maven dependency in pom.xml file of your project:

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

2. Stand alone Java Project

If you are going to create a standalone java project then you have to add the following jar files into your java build path:

  1. poi-4.0.1.jar
  2. poi-ooxml-4.0.1.jar
  3. poi-ooxml-schemas-4.0.1.jar
  4. xmlbeans-3.0.2.jar
  5. curvesapi-1.05.jar
  6. commons-codec-1.11.jar
  7. commons-collections4-4.2.jar
  8. commons-compress-1.18.jar
  9. commons-math3-3.6.1.jar

Download Apache POI Jars

You can easily download all the above jars at one place: Download Apache POI Jars

download poi jars

Steps to add jar files into java build path

In Eclipse, right-click on your Project > Properties > select Java Build Path > Libraries Tab > Add External JARs… then choose above mention jars after that click on Apply and Close button as you can see in the below image:

Java Build Path Setup

Apache POI – How to Build?

You are going to see, how to create a sample maven application in Eclipse and add the maven dependency:

Steps to build maven application

Step-1: Create new maven project by clicking File Menu > New > Maven Project and simply click on Next button as below image:

new maven project dialog

Step-2: Select the maven archetype: maven-archetype-quickstart and click on Next as below image:

maven archetype quickstart

Step-3: Provide Group Id: com.javacodepoint and Artifact Id: DemoApplication and click on Finish button as below image:

creating maven project

Step-4 : Now add the below maven dependency into pom.xml file:

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

Once you add the above dependency you would see the poi jars get added into your project as you can see in the below image:

maven dependencies for poi-4.01

That’s all, now you are ready with the Apache POI environment setup.

Conclusion

In this article, you have seen how to get started with Apache POI for manipulating the Microsoft Excel file(XLS and XLSX) format. Here you have seen we have taken Apache poi-4.0.1 version to demonstrate it.

Share with friends

Leave a Comment

Your email address will not be published. Required fields are marked *