Office Files (Word and Excel with Apache POI)

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

The reference material consulted while preparing these pages is listed in the section bibliography.

Business backends constantly exchange spreadsheets and Word documents with their users: a catalogue exported to Excel, a nightly loans report, a letter generated from a template, a product list uploaded by an operator. This section is a practical, example-driven guide to doing that on a Java server with Apache POI. Versions and dates are re-verified when each page is written and stated as of the date checked.

Running scenario: Bookshelf

Every page uses the same example, the back office of the Bookshelf store used by other sections, so readers can compare approaches. The files involved are:

  • books-inventory.xlsx: the catalogue export, with a styled header, number and date formats, totals formulas, an auto-filter, a frozen header row, a data-validation column and a chart.

  • loans-report.xlsx: a large streaming export of every loan.

  • loan-letter.docx and monthly-report.docx: Word documents with headings, a table, an image, a header and footer and page numbers, generated from scratch and from a template.

  • books-import.xlsx: a catalogue upload with header mapping, per-row validation and an annotated error workbook returned to the user.

  • book-request-form.docx: a Word form from which tables and content controls are extracted.

No example uses real secrets, passwords or personal data; encryption examples read the password from configuration.

Export path and import path

The section is organised around two directions of data flow.

  • Export path. The server builds a workbook or a document from its own data and sends it to the user, or stores it: styles, formulas, layout, streaming large result sets and download endpoints.

  • Import path. The user uploads a file that the server must treat as untrusted input: type detection, reading cells and runs, event-based reading of large files, validation, error reporting and security limits.

Word and Excel are the focus. PowerPoint (HSLF and XSLF), Outlook (HSMF), Visio (HDGF and XDGF) and Publisher (HPBF) are POI components too; they are described only in one table on the introduction page.

Version baseline

Values checked on 2026-10-09 against Maven Central and the Apache POI website.

Component Version used in this section

Apache POI

5.5.1 (released 30 November 2025). Differences in the 6.0 line, which has not been released yet, are noted on each page.

Apache XMLBeans

5.4.1

spring-batch-excel

0.3.0 (community extension, readers only)

Spring Boot

4.1.x, on Spring Framework 7

Jakarta EE

11 (Servlet 6.1, RESTful Web Services 4.0, Validation 3.1)

Java

21 or later (POI 5.5.x itself needs Java 8; POI 6.0 is announced to need JDK 17)

Choose your page

flowchart TD S["What do you need?"] --> E["Produce a file"] S --> I["Read an uploaded file"] E --> EX["Excel: workbook, styles, formulas, streaming"] E --> EW["Word: documents, tables, images, templates"] I --> IX["Excel: usermodel or event reading, validation"] I --> IW["Word: text, tables and form extraction"] EX --> SEC["Security, limits and encryption"] EW --> SEC IX --> SEC IW --> SEC SEC --> SRV["Server workflows: download, upload, batch"]

Pages

The outline covers foundations (component map, setup and file formats), Excel, Word, cross-cutting topics (text extraction, metadata, encryption and security) and server workflows (downloads, uploads, validation, batch jobs, testing and migration), and ends with a downloadable cheat sheet. Pages are listed in reading order.

Foundations

Excel

Word

Cross-cutting topics

Server import and export workflows

Bibliography

The pages of this section are written against the official documentation listed here, verified on 2026-10-09 against the versions stated in the version baseline above. Each page lists the subset it used under its own == References.

Libraries POI depends on or integrates with