Apache POI is an open-source Java library that allows you to create, read, modify, and display Microsoft Office files like Excel, Word, and PowerPoint. Since Java does not natively support Office file formats, POI provides a convenient API for working with these files.
- Supports both XLS (Excel 97-2007) and XLSX (Excel 2007+) formats.
- Provides HSSF for XLS files and XSSF for XLSX files.
- SXSSF API allows handling very large Excel sheets with low memory usage.
- Supports both User Model (object-oriented) and Event Model (token-based, memory-efficient) for Excel processing.
Supports advanced Excel features:
- Formulas
- Cell styles (colors, borders, fonts)
- Headers and footers
- Data validations
- Images and hyperlinks
Common POI Components
Component | Use Case |
|---|---|
HSSF | Read/write Excel .xls files |
XSSF | Read/write Excel .xlsx files |
POIFS | Core file system for reading Office files |
HWPF | Read/write Word .doc files |
HSLF | Read/edit PowerPoint presentations |
Environment Setup
Maven Dependency: For Maven projects, add the POI dependency in your pom.xml using the following code.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
Without Maven: Download the following JAR files from the POI download page and add them to your project:
- poi-3.10-FINAL.jar
- poi-ooxml-3.10-FINAL.jar
- poi-ooxml-schemas-3.10-FINAL.jar
- commons-codec-1.5.jar
- xml-apis-1.0.b2.jar
- stax-api-1.0.1.jar
- xmlbeans-2.3.0.jar
- dom4j-1.6.1.jar
Note: In Eclipse, go to Window → Show View → Other → Maven → Maven Repositories to manage dependencies.