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 the Apache poi-4.0.1 version so it required JDK 1.8+

How to Install Apache POI?

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

  1. Maven Project
  2. Stand alone Java Project

1. Apache poi Maven Project

If you are going to create a maven project for poi, then you have to add the following maven dependency in the 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. Apache poi standalone Java Project

If you are going to create a standalone java project for poi 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

How to download Apache POI?

You can easily download all the above jars for poi in one place: Download Apache POI Jars

download apache poi jars

Steps to add poi 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:

Apache poi Java Build Path Setup

How to create an Apache POI maven application?

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

Steps to create poi maven application

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

apache poi new maven project dialog

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

apche poi maven archetype quickstart

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

apache poi creating maven project

Step-4: Now add the below maven dependency into the 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.

Related Articles:

Share with friends

Leave a Comment

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