Fact-checked by Grok 2 weeks ago

Apache POI

Apache POI is an open-source Java library developed and maintained by , providing a set of APIs for creating, reading, modifying, and writing various binary and XML-based file formats used by applications. It supports manipulation of documents in formats such as Excel spreadsheets (.xls and .xlsx), Word documents (.doc and .docx), and PowerPoint presentations (.ppt and .pptx), enabling developers to automate tasks like data extraction, report generation, and file conversion in Java-based applications. The project addresses both legacy OLE2 Compound Document formats (e.g., pre-2007 Office files) and modern (OOXML) standards, making it a versatile tool for cross-platform compatibility without requiring software. The library's core components include HSSF and XSSF for Excel handling—where HSSF targets the older binary .xls format and XSSF manages the XML-based .xlsx—along with a unified model for streamlined spreadsheet operations across both. For Word processing, it offers HWPF for .doc files and XWPF for .docx, while PowerPoint support comes via HSLF (.ppt) and XSLF (.pptx). Additional modules extend functionality to other Microsoft formats, such as HSMF for .msg files, HDGF and XDGF for Visio diagrams, and utilities like POIFS for OLE2 filesystem access and HPSF for document properties, broadening its utility in enterprise environments for tasks including text extraction in web crawlers or integration with tools like Apache Tika. Originating as a subproject of the before becoming a top-level Apache initiative, POI has evolved to require Java 8 or higher since version 4.0.1, with enhanced JDK 11 support introduced in 2019 and ongoing updates for and performance. Its latest stable release, version 5.5.0, arrived in November 2025, incorporating updates including the fix for CVE-2025-31672 in version 5.4.0 and fostering contributions following the to Git-based development in July 2025. Widely adopted in open-source and for its pure Java implementation and avoidance of proprietary dependencies, Apache POI remains a foundational resource for handling Office-compatible documents programmatically.

Introduction

Overview

Apache POI is a pure Java library that serves as an API for reading, writing, and modifying file formats, encompassing both binary formats derived from the OLE 2 Compound Document standard and XML-based formats such as (OOXML). The library enables programmatic manipulation of these documents in applications, providing a standardized interface for operations on office-related files without reliance on . Its primary applications include handling Excel spreadsheets for data processing and reporting, Word documents for text and layout management, PowerPoint presentations for slide creation and editing, and Visio diagrams for flowchart and schematic manipulation. These capabilities support a wide range of use cases in , such as automated report generation, document templating, and data extraction from legacy office files. Key benefits of Apache POI include its cross-platform compatibility due to its implementation in pure , eliminating the need for installations on the host system, and its open-source nature under the 2.0, which permits free use, modification, and distribution. The project originated as a Java port of Microsoft's 2 file formats and is governed by , ensuring community-driven development and maintenance.

Licensing and Development

Apache POI is released under the 2.0, a permissive that permits free use, modification, and distribution of the software, provided that appropriate attribution is given to and any included copyright notices. This license ensures compatibility with a wide range of projects while requiring that modified versions carry a similar notice and that the original copyright holders are acknowledged. The project operates as a top-level Apache project under the governance of the Apache Software Foundation, having transitioned from the Jakarta Project subproject in June 2007. Development is driven by a community of volunteer contributors who follow the Apache project's meritocratic model, where committers review and integrate contributions to maintain code quality and alignment with the project's goals. Community engagement occurs through dedicated mailing lists, such as [email protected] for technical discussions and [email protected] for general support queries, hosted on the Apache infrastructure. Issues and bugs are tracked via the Apache Bugzilla system, where users can report problems and submit patches for review. Contribution guidelines emphasize submitting code via Bugzilla, adhering to coding standards, and granting the Apache Software Foundation a broad license to contributed works to facilitate ongoing development. To extend its reach beyond , Apache POI provides official bindings for , enabling direct access from Ruby applications. Additionally, modules integrate POI with ecosystems, including for scalable processing of Office formats in distributed environments.

History

Origins and Early Development

Apache POI originated in April 2001 as the "Poor Obfuscation Implementation," a playful acronym referencing the obfuscated nature of Microsoft's 2 Compound Document Format. The project was initiated by Andrew Oliver, who required a Java-based solution for generating Excel reports but found proprietary s prohibitively expensive at around $10,000. Early development focused on creating POIFS (Poor Obfuscation Implementation File System), a pure implementation for handling the 2 structure underlying legacy binary files, with contributions from Marc Johnson who had independently developed a similar library. The primary goal of POI's early phase was to offer open-source, platform-independent alternatives to Microsoft's proprietary COM-based , enabling Java developers to read, write, and manipulate documents without reliance on native code or commercial tools. This addressed a critical need in the Java ecosystem for cross-platform , particularly for enterprise applications requiring Excel and Word . Initial components emerged in the early 2000s, including HSSF (Horrible Format) for handling Excel . files, which built upon POIFS to support basic reading and writing operations by mid-2001. Similarly, HWPF (Horrible Word Processor Format) was developed to process Word .doc files, providing low-level access to streams and initial high-level interfaces for text and modification, as outlined in the project's vision for version 2.0. Under the Jakarta Project, POI grew from a short-term contract tool into a robust subproject, with its first public release in August 2001 and expanded features like a serializer framework by 2002. The project attracted contributors such as Nicola Ken Barozzi for bug fixes and documentation, and Glen Stampoultzis for graphing enhancements, fostering a collaborative community. In June 2007, POI graduated from Jakarta to become an independent top-level project, gaining broader governance and visibility to support ongoing evolution toward modern formats.

Office Open XML Integration

Microsoft's introduction of (OOXML) as the default format in Office 2007 marked a significant shift from proprietary binary formats to an open, XML-based standard, aiming to enhance interoperability and long-term document preservation. This change prompted the Apache POI project to extend its capabilities beyond legacy binary support, responding with the release of version 3.5 in October 2009, which introduced comprehensive read and write functionality for OOXML files. To facilitate this integration, Apache POI collaborated with through the consultancy firm Sourcesense, which received funding from to contribute code and expertise aligned with the ECMA-376 standard (later ISO/IEC 29500). This partnership focused on ensuring interoperability by incorporating contributions from the OpenXML4J library, a pure of the underlying OOXML. The effort addressed initial concerns over patent licensing under 's Open Specification Promise, ultimately enabling POI to support OOXML without proprietary dependencies. Key additions in POI 3.5 included the XSSF component for manipulating .xlsx , XWPF for .docx word processing documents, and XSLF for .pptx presentations, providing high-level that mirror the existing binary format support while leveraging a unified (SS) model for cross-format operations. These components enabled full read/write access to core OOXML features, such as structured XML parts for content, styles, and relationships, covering approximately 90% of the functionality available in POI's binary counterparts at the time. Developing this support presented challenges in handling OOXML's complex structure, which packages multiple interrelated XML files within a archive, requiring robust parsing without native libraries. POI addressed this by integrating OpenXML4J for package management and XMLBeans for schema validation and type-safe XML processing, ensuring compliance with ECMA-376 specifications while mitigating issues like memory consumption for large documents and potential security vulnerabilities in XML parsing. This approach allowed Java developers to achieve seamless interoperability with modern Office formats independently.

Recent Developments and Roadmap

Following the integration of support around 2010, Apache POI has seen steady post-2010 growth in its presentation and diagramming components. Enhancements to XSLF, the OOXML-based PowerPoint module, have included improved handling of complex elements such as SmartArt diagrams, added in version 5.2.2 to enable better programmatic creation and manipulation of slide layouts. Similarly, the XDGF module for Visio OOXML (VSDX) files has expanded with support for advanced shapes like polylines and elliptical arcs in version 5.3.0, facilitating more comprehensive read access to modern Visio diagrams. Recent development efforts have targeted refinements in auxiliary components for enhanced . The HSMF module, which handles Outlook MSG files, received improvements to attachment extraction in version 5.2.4, allowing more reliable retrieval of embedded files and headers from email messages. Additionally, version 5.3.0 introduced SVG image integration in the XWPF Word processing module, enabling the embedding and rendering of scalable vector graphics within documents for improved visual fidelity. Looking ahead, the project roadmap emphasizes broadening format coverage and robustness. Version 5.5.0, released on November 15, 2025, introduced initial for reading XLSB binary Excel files, addressing a gap in binary spreadsheet handling beyond traditional . Ongoing community efforts focus on expanding the HPBF module for files and the HMEF module for Transport Neutral Encapsulation Format (TNEF) attachments, aiming for fuller read/write capabilities to support legacy email and publishing workflows. Community-driven priorities include regular dependency upgrades to bolster and . Recent releases, such as 5.4.0, 5.4.1, and 5.5.0, incorporated updates to libraries like XMLBeans, Commons Compress, Bouncy Castle (to 1.82 in 5.5.0), Commons-IO (to 2.21.0), and PDFBox (to 3.0.6), mitigating vulnerabilities while noting potential behavior changes with JDK 24 locale providers for modern runtime environments.

Supported Formats and Components

Binary Formats (OLE 2)

Apache POI provides comprehensive support for legacy binary formats based on the OLE 2 Format, which structures files as containers embedding multiple streams of data, such as text, images, and metadata, in documents like Excel (.xls), Word (.doc), and PowerPoint (.ppt) files from versions 97-2003. This format, developed by in the early , allows for compound files that behave like a within a single file, enabling the storage of hierarchical data streams and properties. POIFS, the foundational component, implements this OLE 2 structure in pure , providing read and write access to the underlying filesystem without interpreting application-specific content, serving as the base for higher-level POI modules. The core components for Office applications leverage POIFS to handle specific binary formats. HSSF enables full read and write operations for Microsoft Excel 97-2003 (.xls) files, allowing manipulation of spreadsheets, formulas, charts, and formatting through a user-friendly API. HSLF offers similar read and write support for PowerPoint 97-2003 (.ppt) files, supporting the creation, modification, and extraction of slides, text, images, embedded objects, and sounds. HWPF provides read access and limited write capabilities for Word 97-2003 (.doc) files, focusing on text extraction, paragraph and section handling, and basic conversions to HTML or XSL-FO, though it supports only Word 6/95 in a limited read-only mode. Auxiliary components extend OLE 2 handling to property sets and other formats. HPSF reads and writes OLE 2 property sets, which store document such as , , creation date, and custom properties in files. For specialized applications, HDGF offers read-only, low-level access to Visio 97-2003 (.vsd) files, primarily for text extraction with limited diagram parsing. HPBF provides read-only support for Publisher 98-2007 (.pub) files, enabling basic text extraction in an early-stage implementation. HMEF handles read-only processing of Transport Neutral Encapsulation Format (TNEF) files, such as winmail.dat attachments from , for extracting text and attachments. HSMF delivers partial read-only access to .msg files, extracting message text and select attachments while navigating the OLE 2 structure. Despite robust read support, limitations persist in write functionality for some components due to the inherent complexity of the 2 format, particularly in HWPF where synchronized updates to text buffers and property structures can lead to incomplete or invalid files without thorough error checking. These binary formats contrast with the modern XML-based (OOXML) standards introduced in 2007, which POI addresses separately for enhanced interoperability.

XML-Based Formats (OOXML)

The Office Open XML (OOXML) format, standardized as ECMA-376, defines a zipped package structure for modern documents, including .xlsx for spreadsheets, .docx for word processing files, and .pptx for presentations. This XML-based approach enables better and extensibility compared to earlier binary formats, with documents composed of multiple XML parts packaged in a ZIP container along with relationships and . Apache POI provides support for OOXML through dedicated components that enable read and write operations for core applications, with varying levels of completeness across . The XSSF handles Excel 2007 and later files (.xlsx), offering a pure implementation for creating, reading, and modifying spreadsheets while adhering to the SpreadsheetML subset of ECMA-376. Similarly, XWPF supports Word 2007+ documents (.docx) via WordprocessingML, allowing manipulation of text, paragraphs, tables, and styles with read and write capabilities for core features, though support is moderately functional and not all advanced Word features are implemented. For presentations, XSLF provides support for PowerPoint 2007+ files (.pptx) using PresentationML, enabling basic creation and editing of slides, shapes, and animations, though it remains in . Beyond the primary suites, POI includes specialized support for diagramming formats. XDGF offers read-only access to Visio 2007+ diagrams (.vsdx), providing low-level for parsing XML streams and chunks without write functionality. Drawing elements across OOXML documents are handled via XDDF, which supports the XML-based DrawingML for charts, shapes, and graphics, contrasting with the binary DDF used in legacy formats. OOXML support in POI excels in handling large files through streaming options like SXSSF for Excel, which reduces memory usage by writing rows to disk incrementally, enabling efficient processing of datasets that exceed the practical limits of binary formats. This aligns with ECMA-376's emphasis on standards compliance, ensuring generated files are compatible with and other conformant applications.

Auxiliary Components

Apache POI provides several auxiliary components that support non-core functionalities, such as handling, graphics rendering, and parsing of specialized formats, thereby extending its utility beyond primary document manipulation. These components facilitate integration with the 2 compound document structure and related ecosystems, enabling developers to access properties, drawings, and email-related files without relying solely on the core HSSF, XSSF, or XWPF modules. They are particularly valuable for bridging gaps in legacy and auxiliary tasks. The POIFS (POI Filesystem) component serves as the foundational layer for all 2-based compound documents in Apache POI, implementing a pure representation of the OLE 2 Compound Document format. It abstracts the underlying filesystem structure, allowing read and write operations on binary streams within files like older documents, and is essential for any POI module that interacts with OLE 2 containers. POIFS enables the parsing and creation of compound files by treating them as a virtual directory system, supporting legacy code integration such as MFC property sets, though it is not intended for direct document creation—instead, it underpins higher-level APIs. HPSF (Horizontal Property Set Format) handles 2 property sets, providing read and write access to document , including summary information like title, author, creation date, and custom properties in files such as Word, Excel, and PowerPoint. It processes property set streams generically, not limited to formats, and supports extraction of thumbnail images alongside standard and user-defined properties. This component is crucial for management in documents, allowing programmatic inspection and modification of these elements within a POIFS-backed filesystem. For drawing and graphics, the DDF (Dreadful Drawing Format) component decodes the Drawing format, known as Escher, which manages binary and shapes in 2 documents. It provides classes for parsing Escher records, including drawing groups, shapes, and , enabling the handling of embedded drawings in formats like older Excel and PowerPoint files. Complementing this, XDDF (XML Drawing Drawing Format) addresses OOXML equivalents through its usermodel package, supporting the creation and manipulation of elements such as charts, shapes, and diagrams in modern formats. XDDF offers high-level abstractions for elements like chart data series, axes, and legends, facilitating graphics integration in XML-based documents. HSMF (Horrible SMF) extends POI's capabilities to MSG files, offering low-level read access to their contents and enhancements for extracting textual elements like sender, subject, and body, along with attachments. Located in the POI scratchpad module, it includes tools for rendering MSG text and accessing MAPI properties, though functionality remains under with no write support. Similarly, HMEF (Horrible MEF) parses winmail. files, which are Transport Neutral Encapsulation Format (TNEF) attachments from and , providing read-only extraction of RTF message bodies, attachments, and attributes such as subject and filenames. It features utilities like content extractors for saving attachments to directories, aiding in the processing of encoded artifacts. These specialized components are often used alongside core POI modules for comprehensive document ecosystem handling.

Architecture

Modular Design

Apache POI employs a modular architecture designed to enhance extensibility, maintainability, and performance, particularly for handling diverse Microsoft Office file formats. Central to this design are principles such as separation of concerns, where independent modules address specific formats like OLE 2 and OOXML, allowing developers to include only necessary components without loading the entire library. Additionally, an event-based model facilitates streaming processing of large files, reducing memory usage by parsing documents incrementally rather than loading them fully into memory; for instance, the SAX-based event API in XSSF enables efficient reading of large XLSX files. At its core, the architecture features layered components that abstract underlying file structures. The POIFS (POI Filesystem) layer serves as the foundation for OLE 2 binary formats, providing a unified filesystem interface for compound documents such as older Excel (XLS) and Word (DOC) files, enabling read/write operations on their hierarchical storage. For XML-based OOXML formats, POI utilizes a unified handling approach through XMLBeans, which compiles schemas into Java classes for structured access to elements in files like XLSX and DOCX; this integration supports both the HSSF (for binary Excel) and XSSF (for XML-based Excel) components without overlapping responsibilities. The modular design is reflected in the project's JAR file organization, which promotes selective dependency management. The core poi.jar contains essential utilities, including the POIFS layer and basic interfaces shared across formats. The poi-ooxml.jar extends this with OOXML-specific support, incorporating XMLBeans for parsing and dependencies like OpenXML4J for package handling. Optional modules, such as poi-scratchpad.jar, provide implementations for legacy or auxiliary formats like older PowerPoint (PPT) and Publisher files, allowing users to avoid including unused code in their applications. Extensibility is a key aspect of POI's architecture, achieved through a plugin-like structure that accommodates custom formats and third-party integrations. Developers can contribute or extend modules via the project's repository, where additional software for niche formats is maintained; this enables seamless collaboration with tools like Tika for content extraction or for XML processing pipelines. Such design ensures that POI remains adaptable to evolving standards without disrupting core functionality.

API Structure and Dependencies

Apache POI's API is organized into distinct layers to balance ease of use with fine-grained control over document manipulation. The high-level Usermodel layer, accessible via packages such as org.apache.poi.ss.usermodel for , provides an abstracted, format-agnostic interface that models documents as familiar structures like , sheets, rows, and cells. Central to this layer is the Workbook interface, which serves as the entry point for creating, reading, or modifying documents, with implementations like HSSFWorkbook for binary Excel (.xls) files and XSSFWorkbook for XML-based Excel (.xlsx) files. This design allows developers to perform common operations without needing to understand the underlying file format specifics. Complementing the Usermodel, POI includes lower-level APIs for direct interaction with the native structures of supported formats. For binary OLE2-based files, such as legacy Excel or Word documents, the HSSF (org.apache.poi.hssf) and HWPF (org.apache.poi.hwpf) packages expose record-oriented structures, enabling precise manipulation of internal elements like cell records or paragraph runs. Similarly, for OOXML formats, the XSSF (org.apache.poi.xssf) and XWPF (org.apache.poi.xwpf) modules provide access to the ZIP-packaged XML parts, including streams for sheets, styles, and relationships, which is essential for advanced customizations or optimizations not exposed at the Usermodel level. These low-level interfaces are particularly useful for handling format-specific features or repairing corrupted files. Apache POI requires 8 or newer as a , with version 4.0.1 marking the shift to this minimum for full compatibility, including built-in STaX support for XML processing. Releases, such as 5.5.0 (as of November 2025), maintain compatibility with versions like Java 11, 17, and 21, while supporting modular builds via JDK 11 or later. The core poi library depends on a small set of required external components, including Codec for binary encoding and decoding tasks. For OOXML functionality, the poi-ooxml artifact is necessary and includes optional integration with XMLBeans (version 5.3.0 or compatible) for comprehensive schema handling; alternatively, poi-ooxml-lite omits full schemas to minimize dependencies and bundle size, relying instead on abbreviated OOXML definitions. Logging is handled optionally through frameworks like 2.x (version 2.24.3 as of POI 5.5.0) or , allowing capture of internal diagnostics without mandatory inclusion. Distributions of Apache POI are provided as artifacts compatible with and , hosted on the Maven Central Repository under the org.apache.poi groupId. Key artifacts include poi for foundational classes, poi-ooxml for XML formats, and specialized ones like poi-scratchpad for auxiliary components; transitive dependencies are resolved automatically by build tools. To ensure and integrity, binary releases include PGP signatures verifiable with Apache's keys, alongside SHA-512 checksums for downloaded JARs and tarballs. In terms of performance, POI incorporates SXSSF as a specialized extension within the Usermodel for writing large .xlsx files with constrained memory. The SXSSFWorkbook class implements a streaming approach, retaining only a configurable window of recent rows in memory (defaulting to 100) while flushing older ones to temporary disk files, thereby enabling processing of datasets far exceeding available —such as millions of rows—without out-of-memory errors. This comes at the expense of forward-only access and no support for modifications after writing, making it ideal for one-pass generation scenarios.

Usage

Basic Operations

Apache POI provides a straightforward means to integrate its libraries into projects, primarily through dependency management tools like . To enable basic operations on formats, developers add the core poi artifact for foundational functionality and the poi-ooxml artifact for support of XML-based formats such as Excel (.xlsx) and Word (.docx). The following dependencies can be included in the project's pom.xml file, specifying the latest stable version (e.g., 5.5.0 as of November 2025):
xml
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>5.5.0</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.5.0</version>
</dependency>
These dependencies ensure access to the necessary classes for handling (OOXML) files without requiring manual JAR management. Reading files with Apache POI begins with loading a from an input source, such as a , using format-specific implementations. For Excel 2007+ (.xlsx) files, the XSSFWorkbook class is employed to create a instance from an InputStream. Once loaded, extraction involves navigating sheets, rows, and s to retrieve values. For instance, the following code demonstrates opening an Excel and printing the value of a specific :
java
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.[Cell](/page/Cell);
import java.io.FileInputStream;

try (FileInputStream file = new FileInputStream("example.xlsx");
     XSSFWorkbook workbook = new XSSFWorkbook(file)) {
    Sheet sheet = workbook.getSheetAt(0);
    Row row = sheet.getRow(0);
    [Cell](/page/Cell) cell = row.getCell(0);
    System.out.println(cell.getStringCellValue());  // Extracts string value from cell A1
} catch (Exception e) {
    e.printStackTrace();
}
This approach allows for simple , with cell values accessed via methods like getStringCellValue(), getNumericCellValue(), or getBooleanCellValue() depending on the 's type. Writing files follows a symmetric pattern, starting with the creation of a new workbook, followed by populating its structure with sheets, rows, and cells, and finally serializing to an output . Using XSSFWorkbook for .xlsx output, developers can build content programmatically and save it to a or . The example below creates a basic Excel file with a single row of data:
java
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.[Cell](/page/Cell);
import java.io.FileOutputStream;

XSSFWorkbook [workbook](/page/Workbook) = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet1");
Row row = sheet.createRow(0);
[Cell](/page/Cell) cell = row.createCell(0);
cell.setCellValue("Hello, Apache POI!");

try (FileOutputStream fileOut = new FileOutputStream("output.xlsx")) {
    workbook.write(fileOut);
} catch (Exception e) {
    e.printStackTrace();
} finally {
    workbook.close();
}
This process ensures the generated file adheres to the OOXML standard, enabling compatibility with . Simple examples illustrate POI's utility for everyday tasks, such as incorporating s into spreadsheets. To create a basic Excel sheet with a , a is initialized, a sheet and row are added, and the is set on a , which evaluates upon opening in Excel. Consider this code snippet that sums values in cells A1, B1, and A2:
java
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.[Cell](/page/Cell);
import java.io.FileOutputStream;

XSSFWorkbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet1");

// Populate data cells
Row dataRow = sheet.createRow(0);
dataRow.createCell(0).setCellValue(10);
dataRow.createCell(1).setCellValue(20);
Row secondRow = sheet.createRow(1);
secondRow.createCell(0).setCellValue(30);

// Add SUM formula in A3
Row formulaRow = sheet.createRow(2);
Cell formulaCell = formulaRow.createCell(0);
formulaCell.setCellFormula("SUM(A1:B2)");

try (FileOutputStream fileOut = new FileOutputStream("formula-example.xlsx")) {
    workbook.write(fileOut);
} finally {
    workbook.close();
}
The formula "(A1:B2)" computes the total of the preceding cells when the file is loaded. For Word documents, basic reading operations involve loading a .docx file with XWPFDocument and iterating through its paragraphs to extract text. This provides a simple way to parse document content without delving into styling or formatting details. The following example reads and prints all paragraphs from a Word file:
java
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import java.io.FileInputStream;

try (FileInputStream file = new FileInputStream("example.docx");
     XWPFDocument document = new XWPFDocument(file)) {
    for (XWPFParagraph paragraph : document.getParagraphs()) {
        System.out.println(paragraph.getText());
    }
} catch (Exception e) {
    e.printStackTrace();
}
Component selection depends on the file format, with XSSF and XWPF suited for OOXML-based Excel and Word files, respectively.

Advanced Features and Best Practices

Apache POI provides robust support for advanced document manipulation, enabling developers to incorporate complex elements such as charts and images into Excel and PowerPoint files, as well as apply sophisticated styling to Word documents. For Excel workbooks, charts can be created and inserted using the XSSFChart and XDDFChartData APIs, which allow for the generation of various chart types like bar, line, and pie charts by defining data series, axes, and legends programmatically. Similarly, images can be embedded in Excel cells or sheets via the XSSFClientAnchor and XSSFDrawing classes, supporting formats like and . In PowerPoint presentations, the HSLFSlideShow or XMLSlideShow classes facilitate adding images to slides through AddPicture and Anchor mechanisms, while charts are handled via the XDDFChart framework for OOXML-based files, ensuring compatibility with PowerPoint's native rendering. For Word documents, styling involves the XWPFRun and XWPFParagraph APIs to set fonts, colors, and sizes—such as applying bold italics with run.setBold(true); run.setItalic(true);—and constructing tables using XWPFTable with customizable borders, cell merges, and nested structures for complex layouts. To handle large-scale efficiently, Apache POI offers streaming modes that minimize usage. The SXSSF (Streaming XSSF) implementation is designed for writing massive Excel files, where it flushes rows to disk after a configurable window size (default 100 rows), preventing out-of-memory errors for datasets exceeding hundreds of thousands of rows. This mode sacrifices for sequential write performance, making it ideal for generating reports from pipelines. For reading huge files without loading everything into , the event-based parsing model uses the XSSFReader and XMLEventReader to process XML parts incrementally, extracting specific sheets or cells on-the-fly via SAX-like event handlers. Best practices in Apache POI usage emphasize robustness and performance optimization. Error handling for corrupt files should involve try-catch blocks around workbook creation, using POIXMLException or OfficeXmlFileException to detect and recover from malformed OLE2 or OOXML structures, often by validating file integrity with tools like Microsoft's Open XML SDK before processing. Thread-safety is limited; POI objects like are not thread-safe by design, so applications must synchronize access using locks or create instance-per-thread to avoid concurrent modification exceptions, particularly in multi-threaded environments like web servers. Common pitfalls include improper formatting in HSSF workbooks, where Java's objects must be converted via HSSFDateUtil.getJavaDate() to match Excel's system, preventing shifts in epoch dates (e.g., 1900 vs. 1904 leap year bugs). Integrations with modern frameworks enhance POI's utility in enterprise applications. When used with , POI can be configured as a dependency in or builds, with services leveraging @Autowired for batch Excel generation in APIs, such as exporting query results to OOXML files via custom controllers. For big data scenarios, POI pairs with or ; in jobs, mappers can output cell data to temporary files, while reducers assemble SXSSF workbooks for distributed report creation, scaling to terabyte-scale datasets without single-node memory constraints. These integrations underscore POI's role in data-intensive workflows, where streaming modes ensure efficient processing.

Version History

Major Releases Up to 2023

Apache POI originated as a subproject of the Jakarta project, with its initial development focusing on Java-based manipulation of binary formats. The project's first major release, version 1.0, was issued on December 30, 2001, introducing basic support for reading and writing Excel files through the HSSF component, which handled the binary format based on the 2 structure. This foundational version established the core architecture for handling binaries without relying on external libraries like itself. Subsequent early releases built upon this base, expanding support for additional Office components. Version 3.0, released in 2007 following the project's transition to a top-level Apache project in June of that year, added significant enhancements to the HWPF module for Word document processing and improved overall stability for HSSF operations. By version 3.5, released on September 28, 2009, Apache POI introduced initial support for the XML-based OOXML formats used in and later, via the XSSF component for Excel spreadsheets and XWPF for Word documents; this marked a pivotal shift toward handling both legacy binary and modern XML formats. These early versions emphasized read support for OOXML, with write capabilities developing gradually in subsequent updates. The mid-period releases focused on modernization and broader compatibility. Version 4.0.0, released on September 7, 2018, dropped support for Java 6 and 7, establishing Java 8 as the minimum requirement, and updated the OOXML schema to version 1.4 to align with evolving standards. This release also advanced write support for OOXML features, including better handling of charts and images in XSSF and XSLF (for PowerPoint). Version 5.0.0, released on January 17, 2021, further refined OOXML integration by upgrading to the ECMA-376 5th edition specification, introducing support for Java's module system, and removing the JAXB dependency to streamline XML processing. It also enhanced the XSLF component for PowerPoint slide manipulation, completing key aspects of OOXML write support across major applications.
VersionRelease DateKey Enhancements
1.0December 30, 2001Basic HSSF for XLS read/write; OLE 2 integration.
3.0June 2007 (re-release as top-level project)HWPF additions for Word; HSSF stability improvements.
3.5September 28, 2009Initial XSSF/XWPF for OOXML read support.
4.0.0September 7, 2018Java 8 minimum; OOXML schema 1.4; enhanced write support.
5.0.0January 17, 2021ECMA-376 5th ed.; Jigsaw modules; XSLF enhancements.
5.2.0January 15, 2022Refactored XSSFReader; XLOOKUP/XMATCH functions; security patches and dependency updates including Log4j 2.x.
Throughout these releases up to 2023, a primary theme was the progressive completion of full read/write capabilities for OOXML formats, transitioning from partial support in 3.5 to comprehensive handling by 5.0. Dependency modernizations were also prominent, such as aligning with 8+ ecosystems and updating logging frameworks to 2.x for better security and performance. Security fixes, including mitigations for vulnerabilities in OOXML parsing, were incorporated in versions like 5.2.0 to address potential denial-of-service risks.

Releases from 2024 Onward

Apache POI 5.3.0, released on July 2, 2024, introduced support for embedding images within XWPF documents, enabling better handling in Word files. This version also upgraded the dependency to version 2.23.1 to address security vulnerabilities and improve logging performance. Additionally, it resolved issues with font rendering in SXSSF workbooks, enhancing reliability for large-scale spreadsheet operations. The subsequent release, 5.4.0 on January 8, 2025, added support for SOURCE_DATE_EPOCH in builds to facilitate reproducible binary outputs without embedded timestamps, aiding in deterministic packaging for pipelines. It implemented stricter validation for invalid file structures, throwing exceptions for zip entries with duplicate names in OOXML files to prevent corruption-related errors. This version further updated to 2.24.3, continuing the focus on security enhancements. Version 5.4.1, issued on April 6, 2025, addressed compatibility challenges with JDK 24 by fixing provider behaviors that affected and number formatting in internationalized applications. It also resolved overflow issues in XSSF for handling large numeric values in Excel sheets, improving during read/write operations. Bug fixes extended to HSMF, refining support for multivalued properties in message attachments to better parse email metadata. Version 5.5.0, released on November 15, 2025, expanded support for formats with an initial for reading XLSB binary Excel files. It also introduced support for the SHEET function and upgraded dependencies including to version 1.19 for enhanced processing and PDFBox to 3.0.5 for improved PDF embedding in documents. As of November 19, 2025, version 5.5.1 is scheduled for release in December 2025, featuring upgrades to commons-io 2.21.0 and PDFBox 3.0.6, along with fixes for missing module-info classes in the 5.5.0 JARs. Recent releases underscore a trend toward greater alignment with modern Java ecosystems, including JDK 24 compatibility and , while expanding niche format support such as HSMF for email forensics and XLSB for binary spreadsheets. These updates build on the cumulative maturity of OOXML handling from prior versions, prioritizing security, stability, and developer productivity in enterprise environments.

References

  1. [1]
    Apache POI™ - the Java API for Microsoft Documents
    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 ...Download Release ArtifactsJavadocsGetting InvolvedPOI-HSSF and POI-XSSFComponent Overview
  2. [2]
    Mirror of Apache POI gitbox. The Java API for Microsoft Documents.
    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.
  3. [3]
    Apache POI™ - Component Overview
    Sep 11, 2025 · The Apache POI project is the master project for developing pure Java ports of file formats based on Microsoft's OLE 2 Compound Document Format.Quick Guide · POI-HSSF and POI-XSSF · HSSF and XSSF Examples · HSSF
  4. [4]
    Apache POI™ - Legal Stuff
    Apache POI releases are available under the Apache License, Version 2.0. See the NOTICE file contained in each release artifact for applicable copyright ...
  5. [5]
    Apache POI™ - Download Release Artifacts
    The latest stable release is Apache POI 5.4.1; Archives of all prior releases. Apache POI releases are available under the Apache License, Version 2.0. See ...
  6. [6]
    Apache POI™ - Contribution Guidelines
    The POI project is OpenSource and developed/distributed under the Apache Software License v2. Unlike some other licenses, the Apache license allows free ...
  7. [7]
    Mailing Lists - Apache POI
    This is the list where participating developers of the POI project meet and discuss issues, code changes/additions, etc.Missing: tracker | Show results with:tracker
  8. [8]
  9. [9]
    POI Ruby Bindings
    The POI library can now be compiled as a Ruby extension, allowing the API to be called from Ruby language programs.
  10. [10]
    Apache POI™ - Related Projects
    poi-visio is a Java library that loads Visio OOXML (vsdx) files and creates an in-memory data structure that allows full access to the contents of the document.
  11. [11]
    Apache POI™ - Project History
    The POI project was dreamed up back around April 2001, when Andrew Oliver landed a short term contract to do Java-based reporting to Excel.
  12. [12]
    POI 2.0 Vision Document - Apache POI
    The HWPF library will provide a set of high level interfaces for reading and writing Microsoft Word 97 file format using pure Java.
  13. [13]
    Apache® POI™ Celebrates 15 Years at The Apache Software ...
    Oct 3, 2016 · 2007–POI becomes an Apache Top-Level Project in June 2007; added support for reading and writing the binary PowerPoint format in v3.0;; 2008 ...
  14. [14]
    Open XML Formats and file name extensions - Microsoft Support
    Microsoft Office uses the XML-based file formats, such as .docx, .xlsx, and .pptx. These formats and file name extensions apply to Microsoft Word, ...
  15. [15]
    Apache POI 3.5 Released with OOXML Support - InfoQ
    Oct 29, 2009 · To work with both OOXML and OLE2 formats POI has a new SS user model (org.apache.poi.ss.usermodel) which provides a common API. The new SS model ...
  16. [16]
    Microsoft and Sourcesense Partner to Contribute to Open Source ...
    Mar 25, 2008 · Apache POI is a Java application programming interface (API) used to access and manage Microsoft Office binary formats, and can be easily ...
  17. [17]
    POI-OpenXML4J - Java API To Access Office Open XML documents
    OpenXML4J is the POI Project's pure Java implementation of the Open Packaging Conventions (OPC) defined in ECMA-376.
  18. [18]
    Document Interoperability Initiative Drives Development of New Tools
    May 18, 2009 · Beta availability of Apache POI 3.5 – Java API to access information in the Open XML Format. This software development kit (SDK) for Java ...Missing: integration | Show results with:integration
  19. [19]
    Frequently Asked Questions - Apache POI
    Sep 11, 2025 · The OOXML support in Apache POI is built on top of the file format XML Schemas, as compiled into Java using XMLBeans. Currently, the compilation ...
  20. [20]
    History of Changes - Apache POI
    HWPF, Fix reading/writing of documents with many columns. fix, 65190, SS_Common, Handle decimal format '0#' the same way as Excel. fix, 66425, POI_Overall ...
  21. [21]
    HDGF and XDGF - Java API To Access Microsoft Visio Format Files
    Sep 11, 2025 · XDGF is the POI Project's pure Java implementation of the Visio XML (VSDX) file format. Currently, HDGF provides a low-level, read-only api for ...
  22. [22]
    POI-HSMF - Java API To Access Microsoft Outlook MSG Files
    POI-HSMF is a Java implementation of the Outlook MSG format, providing low-level read access and access to common textual content.Missing: attachment extraction
  23. [23]
    Java implementation of the OLE 2 Compound Document format
    POIFS is a pure Java implementation of the OLE 2 Compound Document format. By definition, all APIs developed by the POI project are based somehow on the POIFS ...
  24. [24]
    Java API To Access Microsoft Powerpoint Format Files - Apache POI
    Sep 11, 2025 · HSLF is the POI Project's pure Java implementation of the Powerpoint '97(-2007) file format. HSLF provides a way to read, create or modify PowerPoint ...<|control11|><|separator|>
  25. [25]
    HWPF and XWPF - Java API to Handle Microsoft Word Files
    Please note that in version 3.12, due to a bug, you might need to include poi-scratchpad-XXX.jar when using XWPF. This has been fixed again for the next release ...POI-XWPF - A Quick Guide · Overview · A Quick Guide · HWPF Project plan
  26. [26]
    HPSF - Java API for Microsoft Format Document Properties
    HPSF is POI's pure-Java implementation to read and write property sets. The HPSF HOWTO describes what a Java application should do to read a property set using ...
  27. [27]
    POI-HPBF - Java API To Access Microsoft Publisher Format Files
    HPBF is the POI Project's pure Java implementation of the Publisher file format. Currently, HPBF is in an early stage, whilst we try to figure out the file ...
  28. [28]
    Java API To Access Microsoft Transport Neutral Encoding Files (TNEF)
    POI-HMEF is a Java API for accessing TNEF files, used by Outlook and Exchange, providing read-only access to message and attachment attributes.Missing: ongoing | Show results with:ongoing
  29. [29]
    ECMA-376 - Ecma International
    This Standard defines Office Open XML's vocabularies and document representation and packaging. It also specifies requirements for consumers and producers ...
  30. [30]
    Overview (POI API Documentation) - Apache POI
    This package contains classes for decoding the Microsoft Office Drawing format otherwise known as escher henceforth known in POI as the Dreadful Drawing Format ...
  31. [31]
    Apache POI™ - HSSF and XSSF Limitations
    For writing very huge files, there is SXSSFWorkbook which allows to do a streaming write of data out to files (with certain limitations on what you can do as ...
  32. [32]
    Apache POI™ - Component Overview
    ### Summary of Auxiliary Components in Apache POI
  33. [33]
    Apache POI™ - POIFS - Java implementation of the OLE 2 Compound Document format
    ### Summary of POIFS from https://poi.apache.org/components/poifs/index.html
  34. [34]
  35. [35]
    POI-HSSF and POI-XSSF/SXSSF - Java API To Access Microsoft ...
    Sep 11, 2025 · Since 3.8-beta3, POI provides a low-memory footprint SXSSF API built on top of XSSF. SXSSF is an API-compatible streaming extension of XSSF to ...Quick Guide · Examples · The New Halloween Document · Upgrading to POI 3.5...
  36. [36]
    Apache POI SAX Parser: Reading a Large Excel File
    Aug 27, 2023 · Learn to read a large Excel file in Java using the Apache POI and SAX parser library. The SAX parser is an event-based parser.
  37. [37]
    Maven Repository: org.apache.poi
    Apache POI - Java API To Access Microsoft Format Files. License, Apache 2.0. Categories, Excel Libraries. Tags, apachepoiexcelspreadsheet.
  38. [38]
  39. [39]
  40. [40]
  41. [41]
  42. [42]
    History of Changes - Apache POI
    History of Changes. Current releases. The change log for the current release can be found in the home section. Version 2.5.1 ...
  43. [43]
    org.apache.poi » poi » 3.5-FINAL - Maven Repository
    Apache POI Common » 3.5-FINAL ; Apache Software Foundation · http://poi.apache.org/ Inspect URL · Sep 28, 2009 · pom (2 KB) jar (1.4 MB) View All.
  44. [44]
    RELEASE-NOTES-4.0.0.txt - Apache Distribution Directory
    The Apache POI project is pleased to announce the release of POI 4.0.0. Featured are a handful of new areas of functionality, and numerous bug fixes. See ...
  45. [45]
    RELEASE-NOTES-5.0.0.txt - Apache Distribution Directory
    The Apache POI project is pleased to announce the release of POI 5.0.0. Featured are a handful of new areas of functionality, and numerous bug fixes. See ...
  46. [46]
    org.apache.poi » poi » 5.0.0 - Maven Repository
    Apache POI Common » 5.0.0 ; Tags, apachepoiexcelspreadsheet · Apache Software · https://poi.apache.org/ · Date, Jan 17, 2021 · Files, pom (3 KB) jar (2.8 ...
  47. [47]
    org.apache.poi » poi » 5.2.0 - Maven Repository
    Apache POI Common » 5.2.0 ; Date, Jan 15, 2022 · Files, pom (3 KB) jar (2.8 MB) View All · CentralFit2CloudLoeyaeMulesoftSoftLeader · Ranking, #198 in ...
  48. [48]