Apache POI — the Java API for Microsoft Documents
The Apache POI team is pleased to announce the release of 5.2.3. Several dependencies were updated to their latest versions to pick up security fixes and other improvements.
A summary of changes is available in the Release Notes. A full list of changes is available in the change log. People interested should also follow the dev list to track progress.
See the downloads page for more details.
POI requires Java 8 or newer since version 4.0.1.
4 March 2022 — CVE-2022-26336 — A carefully crafted TNEF file can cause an out of memory exception in Apache POI poi-scratchpad versions prior to 5.2.0
Description:
A shortcoming in the HMEF package of poi-scratchpad (Apache POI) allows an attacker to cause an Out of Memory exception. This package is used to read TNEF files (Microsoft Outlook and Microsoft Exchange Server). If an application uses poi-scratchpad to parse TNEF files and the application allows untrusted users to supply them, then a carefully crafted file can cause an Out of Memory exception.
Mitigation:
Affected users are advised to update to poi-scratchpad 5.2.1 or above which fixes this vulnerability. It is recommended that you use the same versions of all POI jars.
10+16+18 December 2021- Log4j vulnerabilities CVE-2021-44228, CVE-2021-45046 and CVE-2021-45105
The Apache POI PMC has evaluated the security vulnerabilities reported for Apache Log4j.
POI 5.1.0 and XMLBeans 5.0.2 only have dependencies on log4j-api 2.14.1. The security vulnerabilities are not in log4j-api — they are in log4j-core.
If any POI or XMLBeans user uses log4j-core to control their logging of their application, we strongly recommend that they upgrade all their log4j dependencies to the latest version (currently v2.17.1) — including log4j-api.
13 January 2021 — CVE-2021-23926 — XML External Entity (XXE) Processing in Apache XMLBeans versions prior to 3.0.0
Description:
When parsing XML files using XMLBeans 2.6.0 or below, the underlying parser created by XMLBeans could be susceptible to XML External Entity (XXE) attacks.
This issue was fixed a few years ago but on review, we decided we should have a CVE to raise awareness of the issue.
Mitigation:
Affected users are advised to update to Apache XMLBeans 3.0.0 or above which fixes this vulnerability. XMLBeans 4.0.0 or above is preferable.
20 October 2019 — CVE-2019-12415 — XML External Entity (XXE) Processing in Apache POI versions prior to 4.1.1
Description:
When using the tool XSSFExportToXml to convert user-provided Microsoft Excel documents, a specially crafted document can allow an attacker to read files from the local filesystem or from internal network resources via XML External Entity (XXE) Processing.
Mitigation:
Apache POI 4.1.0 and before: users who do not use the tool XSSFExportToXml are not affected. Affected users are advised to update to Apache POI 4.1.1 which fixes this vulnerability.
Credit: This issue was discovered by Artem Smotrakov from SAP
26 March 2019 — XMLBeans 3.1.0 available
The Apache POI team is pleased to announce the release of XMLBeans 3.1.0. Featured are a handful of bug fixes.
The Apache POI project has unretired the XMLBeans codebase and is maintaining it as a sub-project, due to its importance in the poi-ooxml codebase.
A summary of changes is available in the Release Notes. People interested should also follow the POI dev list to track progress.
The XMLBeans JIRA project has been reopened and feel free to open issues.
POI 4.1.0 uses XMLBeans 3.1.0.
XMLBeans requires Java 6 or newer since version 3.0.2.
11 January 2019 — Initial support for JDK 11
We did some work to verify that compilation with Java 11 is working and that all unit-tests pass.
See the details in the FAQ entry.
Mission Statement
The Apache POI Project’s mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft’s OLE 2 Compound Document format (OLE2). In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. Apache POI is your Java Excel solution (for Excel 97-2008). We have a complete API for porting other OOXML and OLE2 formats and welcome others to participate.
OLE2 files include most Microsoft Office files such as XLS, DOC, and PPT as well as MFC serialization API based file formats. The project provides APIs for the OLE2 Filesystem (POIFS) and OLE2 Document Properties (HPSF).
Office OpenXML Format is the new standards based XML file format found in Microsoft Office 2007 and 2008. This includes XLSX, DOCX and PPTX. The project provides a low level API to support the Open Packaging Conventions using openxml4j.
For each MS Office application there exists a component module that attempts to provide a common high level Java api to both OLE2 and OOXML document formats. This is most developed for Excel workbooks (SS=HSSF+XSSF). Work is progressing for Word documents (WP=HWPF+XWPF) and PowerPoint presentations (SL=HSLF+XSLF).
The project has some support for Outlook (HSMF). Microsoft opened the specifications to this format in October 2007. We would welcome contributions.
As a general policy we collaborate as much as possible with other projects to provide this functionality. Examples include: Cocoon for which there are serializers for HSSF; Open Office.org with whom we collaborate in documenting the XLS format; and Tika / Lucene, for which we provide format interpretors. When practical, we donate components directly to those projects for POI-enabling them.
Why should I use Apache POI?
A major use of the Apache POI api is for Text Extraction applications such as web spiders, index builders, and content management systems.
So why should you use POIFS, HSSF or XSSF?
You’d use POIFS if you had a document written in OLE 2 Compound Document Format, probably written using MFC, that you needed to read in Java. Alternatively, you’d use POIFS to write OLE 2 Compound Document Format if you needed to inter-operate with software running on the Windows platform. We are not just bragging when we say that POIFS is the most complete and correct implementation of this file format to date!
You’d use HSSF if you needed to read or write an Excel file using Java (XLS). You’d use XSSF if you need to read or write an OOXML Excel file using Java (XLSX). The combined SS interface allows you to easily read and write all kinds of Excel files (XLS and XLSX) using Java. Additionally there is a specialized SXSSF implementation which allows to write very large Excel (XLSX) files in a memory optimized way.
Components
The Apache POI Project provides several component modules some of which may not be of interest to you. Use the information on our Components page to determine which jar files to include in your classpath.
Contributing
So you’d like to contribute to the project? Great! We need enthusiastic, hard-working, talented folks to help us on the project, no matter your background. So if you’re motivated, ready, and have the time: Download the source from the Subversion Repository, build the code, join the mailing lists, and we’ll be happy to help you get started on the project!
Please read our Contribution Guidelines. When your contribution is ready submit a patch to our Bug Database.
Apache POI
POIFS (Poor Obfuscation Implementation File System) — базовый управляющий компонент для всех POI элементов. Он используется для явного чтения различных файлов.
HSSF (Horrible Spreadsheet Format) — компонент, который используется для чтения и записи формата .xls MS-Excel файлов. [3.9]
XSSF (XML Spreadsheet Format) — компонент, который используется для чтения и записи формата .xlsx MS-Excel файлов. [3.9]
HPSF (Horrible Property Set Format) — компонент, который используется для извлечения пропертей из MS-Office файлов. [3.9]
HWPF (Horrible Word Processor Format) — компонент, который используется для чтения и записи формата .doc MS-Word файлов. [3.9]
XWPF (XML Word Processor Format) — компонент, который используется для чтения и записи формата .docx MS-Word файлов. [3.9]
HSLF (Horrible Slide Layout Format) — компонент, который используется для чтения и записи MS-PowerPoint файлов. [3.9]
HDGF (Horrible DiaGram Format) — компонент, который используется для чтения и записи MS-Visio файлов. [3.9]
HPBF (Horrible PuBlisher Format) — компонент, который используется для чтения и записи MS-Publisher файлов. [3.9]
3. Классы и интерфейсы
Workbook — базовый интерфейс для всех классов, которые создают или обрабатывают Excel документы.
- Он находится в org.apache.poi.ss.usermodel пакете. [3.9]
- Его реализуют следующие классы:
- HSSFWorkbook — класс для чтения и записи файлов .xls формата. Поддерживает 1997-2003 версии MS-Office. Он находится в org.apache.poi.hssf.usermodel пакете.
- XSSFWorkbook — класс для чтения и записи файлов .xlsx формата. Поддерживает 2007+ версии MS-Office. Он находится в org.apache.poi.xssf.usermodel пакете.
Sheet — базовый интерфейс для всех классов, которые создают таблицы произвольного типа. Наиболее распространенной таблицей является worksheet, которая представлена сеткой ячеек. [3.9]
- Он находится в org.apache.poi.ss.usermodel пакете.
- Его реализуют следующие классы:
- HSSFSheet — класс для создания excel таблиц и редактирования данных и стилей этих таблиц. Он находится в org.apache.poi.hssf.usermodel пакете.
- XSSFSheet — класс для создания excel таблиц и редактирования данных и стилей этих таблиц. Он находится в org.apache.poi.xssf.usermodel пакете.
Row — базовый интерфейс для всех классов, которые представляют строку таблицы. [3.9]
- Он находится в org.apache.poi.ss.usermodel пакете.
- Его реализуют следующие классы:
- XSSFRow — класс для представления строк в таблице. Он находится в org.apache.poi.xssf.usermodel пакете.
Cell — базовый интерфейс для всех классов, которые представляют ячейки в строках таблицы. [3.9]
- Он находится в org.apache.poi.ss.usermodel пакете.
- Его реализуют следующие классы:
- XSSFCell — класс для представления ячеек в таблице. Он находится в org.apache.poi.xssf.usermodel пакете.
- XSSFCell — класс для представления ячеек в таблице. Он находится в org.apache.poi.xssf.usermodel пакете.
CellStyle — базовый интерфейс для всех классов, которые представляют собой стиль ячейки. [3.9]
- Он находится в org.apache.poi.ss.usermodel пакете.
- Его реализуют следующие классы:
- HSSFCellStyle — класс для представления ячеек в таблице. Он находится в org.apache.poi.hssf.usermodel пакете.
- XSSFCellStyle — класс для представления ячеек в таблице. Он находится в org.apache.poi.xssf.usermodel пакете.
Color — базовый интерфейс для всех классов, которые представляют цвет ячейки. [3.9]
- Он находится в org.apache.poi.ss.usermodel пакете.
- Его реализуют следующие классы:
- HSSFColor — класс для регулирования цвета ячеек в таблице. Он находится в org.apache.poi.hssf.usermodel пакете.
- XSSFColor — класс для регулирования цвета ячеек в таблице. Он находится в org.apache.poi.xssf.usermodel пакете.
Font — базовый интерфейс для всех классов, которые представляют шрифт текста ячейки. [3.9]
- Он находится в org.apache.poi.ss.usermodel пакете.
- Его реализуют следующие классы:
- HSSFColor — класс для регулирования шрифта текста ячеек в таблице. Он находится в org.apache.poi.hssf.usermodel пакете.
- XSSFColor — класс для регулирования шрифта текста ячеек в таблице. Он находится в org.apache.poi.xssf.usermodel пакете.
Hyperlink — базовый интерфейс для всех классов, которые представляют гиперссылку. [3.9]
- Он находится в org.apache.poi.ss.usermodel пакете.
- Его реализуют следующие классы:
- HSSFColor — класс для представления гиперссылки. Он находится в org.apache.poi.hssf.usermodel пакете.
- XSSFColor — класс для представления гиперссылки. Он находится в org.apache.poi.xssf.usermodel пакете.
CreationHelper — базовый интерфейс для всех классов, которые являются используются при вычислении формулы ячейки и для создания гиперссылок. [3.9]
- Он находится в org.apache.poi.ss.usermodel пакете.
- Его реализуют следующие классы:
- HSSFCreationHelper — класс для вычисления формулы ячейки и для создания гиперссылок. Он находится в org.apache.poi.hssf.usermodel пакете.
- XSSFCreationHelper — класс для вычисления формулы ячейки и для создания гиперссылок. Он находится в org.apache.poi.xssf.usermodel пакете.
PrintSetup — базовый интерфейс для всех классов, которые регулируют размер, область, параметры распечатываемой страницы. [3.9]
Apache POI
While developing any application, we may encounter various requirements from the client, which can also include handling the Excel files or showing data to the user in the form of files, so apache poi is an API that solves our problem and manages this kind of work. With the help of this, we can easily handle and manage the MS office files in our application by writing the java code; we must have to do a few configurations in order to use this. This API makes our task easy, quick, and error-free as well, also; we came across a requirement where we have to upload the data of users in the form of files, so in that case also we may require a program that can handle this, so in this place, we can make use of apache POI.








What is Apache POI?
- First of all, this API is provided by Apache Software Foundation, an open-source library, which helps us modify or design our MS files using the java program in place. So, in short, it allows developers or enables us to design, modify, create, and display the MS office files using the Java program.
- This is an API containing the corresponding classes and methods that help us read the user data from the file or write or create any new file based on that user data.
Components Used to Read Apache POI
Given below are the main components which we are going to use while reading Apache POI. This API contains many methods and classes that help us work and handle all the MS office files via the java program.
Web development, programming languages, Software testing & others
- HPBF: This is one of the main components of apache poi, which stands for Horrible Publisher Format; this component is used to read and write the files, which are MS-Publisher files specifically.
- HSSF: This is another component that stands for Horrible Spreadsheet Format, this type of component is particularly used to read and write the xls format of the MS Excel files we have.
- HPSF: This is yet another component that stands for Horrible Property Set Format; this component is basically used to extract the property of the MS Office files, which basically includes the property sets.
- HSLF: This is another component that stands for Horrible Slide Layout Format; this is basically used for the PowerPoint presentations, with the support to the operations like edit, create and read.
- HDGF: This is another component that stands for Horrible Diagram Format; this basically contains and handles the binary files; it internally contains methods and classes to handle the MS Visio-related binary files.
- POIFS: This is yet another com of apache poi, which stands for Poor Obfuscation Implementation File System; this is considered as the basic component or the basic factor of all the poi elements we used. If we want to read a different file type, we can use this by writing code explicitly.
- HWPF: This is another component of apache poi that stands for Horrible Word Processor Format; this component basically supports the MS word files with extension doc.
- XSSF: This is another component of apache poi which stands for XML Spreadsheet Format; this component is basically used to read the xlsx extension files of MS Excel.
- XWPF: This is another component that stands for XML Word Processor Format; this component is basically used to read and write the MS Word files with extension docx.
Dependencies and Apache POI Installation
Given below shows how we can use Apache POI inside our java project to handle the files efficiently.
Maven:
1. Go to the below-mentioned URL and press enter:
URL: https://mvnrepository.com/artifact/org.apache.poi/poi
2. Select the correct version and copy the dependency to your pom.xml.
Code:
Output:

Gradle:
1. If you are using gradle, go to the same URL, choose the correct version, and click on gradle to the gradle standard dependency.
Example:
Implementation group: ‘org.apache.poi’, name: ‘poi’, version: ‘5.0.0’

2. Add to your build.gradle file in the application.
Normal Java Project:
To add the apache poi to the normal java project, follow the below instruction:
a. Download the dependency into your system by going through the below URL.
URL:
b. Extract the folder and place it into the directory you want.

c. Inside eclipse, right-click your project and go to Build Path > Libraries > Add external JARs.
d. Select all the files which are inside (lib, ooxml-lib, and root folder of your poi)
e. Press applies and ok.
Classes:
- HSSFWorkbook: This class is used to create the object of HSSFWorkbook.
- XSSFWorkbook: This class is used to create the object of XSSFWorkbook.
- HSSFSheet: This class is used to create the object of the HSSFSheet.
- XSSFSheet: This class is used to create the object of the XSSFSheet.
- XSSFRow: This is used to implement the rows.
- XSSFCell: This is used to create the cell interface.
- XSSFCellStyle: This class is used to style the cell.
Important Features
- It provides stream-based processing.
- It can handle both XLS and XLSX.
- It provides good support for additional excel features.
- It also requires less memory.
Conclusion
It shows step-by-step usages benefits and features of using Apache POI to read write the MS office file via java program with already declared classes and methods, making it quick and easy for the developer to handle it.
Recommended Articles
This is a guide to Apache POI. Here we discuss the introduction, components used to read apache POI, dependencies & installation, features. You may also have a look at the following articles to learn more –
Name already in use
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.rst
A Java library for reading and writing Microsoft Office binary and OOXML file formats.
The Apache POI Project’s mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft’s OLE 2 Compound Document format (OLE2). In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. Apache POI is your Java Excel solution (for Excel 97-2008). We have a complete API for porting other OOXML and OLE2 formats and welcome others to participate.
OLE2 files include most Microsoft Office files such as XLS, DOC, and PPT as well as MFC serialization API based file formats. The project provides APIs for the OLE2 Filesystem (POIFS) and OLE2 Document Properties (HPSF).
Office OpenXML Format is the new standards based XML file format found in Microsoft Office 2007 and 2008. This includes XLSX, DOCX and PPTX. The project provides a low level API to support the Open Packaging Conventions using openxml4j.
For each MS Office application there exists a component module that attempts to provide a common high level Java api to both OLE2 and OOXML document formats. This is most developed for Excel workbooks (SS=HSSF+XSSF). Work is progressing for Word documents (WP=HWPF+XWPF) and PowerPoint presentations (SL=HSLF+XSLF).
The project has some support for Outlook (HSMF). Microsoft opened the specifications to this format in October 2007. We would welcome contributions.
There are also projects for Visio (HDGF and XDGF), TNEF (HMEF), and Publisher (HPBF).
This library includes the following components, roughly in descending order of maturity: