he purpose of the Jakarta POI open source project is to provide Java with the ability to manipulate file formats based on Microsoft’s OLE 2 Compound Document Format. Currently, the most widely accepted part of the project is the Horrible Spread Sheet Format (HSSF) (click the link to discover a bit of the history behind that name.
HSSF provides:
- An environmental API for read-only access to Excel (97-2000) format.
- A full user model API for creating, reading and modifying the Excel files.
The HSSF framework is divided into the following packages (see Table 1).
Table 1: Packages in the HSSF framework. The table lists the packages in the HSSF framework and the purpose of each.
|
Package |
Purpose |
|
org.apache.poi.hssf.eventmodel |
Handles different events generated in the process of readingand writing Excel documents. |
|
org.apache.poi.hssf.eventusermodel |
Provides classes to read Excel documents. |
|
org.apache.poi.hssf.record.formula |
Contains classes to handle FORMULA used in Excel document. |
|
org.apache.poi.hssf.usermodel |
Contains classes to generate Excel documents. |
|
org.apache.poi.hssf.util |
Contains utility classes to handle different attributes of theExcel document. |
Using these packages you can interact with existing Excel documents and create new ones. Before starting to develop the example, here’s a brief explanation of how the POI models an Excel document.
The Excel Document Model
From the HSSF point of view, the Excel document is divided into a Workbook, one or more Worksheets, Worksheet consists of rows. Rows have multiple cells and cells can have different display attributes and formula attached to them. This overall structure is as depicted in Figure 1.
![]() |
Build a Practical Example To generate this Excel document using HSSF, you must:
You can see that creating the spreadsheet requires separate tasks where you create a worksheet, create rows and cells, create a merged region for the worksheet caption, specify different styles for the cells and create a special type of cell to contain the mathematical formula that calculates the total. Finally, you have to save the workbook in the file system. Creating a new Excel worksheet is simple. First you create a new workbook:
Then you can create a new worksheet within that workbook:
You create rows by calling the Worksheet object’s createRow method. Remember, the row index starts from 0.
To create the merged area for the caption you want to define a merged region from the first to the third row, and from first to the tenth column. Here’s the code:
After creating the caption region, create a cell to contain the caption value.
Because the header row spans multiple rows and columns, the caption “The Bowling Score” will span the defined merged region. Worksheet cells have many display properties that you can control through HSSF. To do that, you create an HSSFCellStyle object and apply styles such as cell alignment (CENTER/LEFT/RIGHT). The following code shows how you can set the background colors and the font style for individual cells.
After defining cell styles, you can apply those styles as follows:
The Worksheet essentially consists of multiple rows and cells. You can create as many rows and cells as you need and then apply styles and assign data to the cells. The following example creates five rows with two cells in each row. The code sets the cell values last, using the setCellValue method.
One of the main advantages of Excel is that you can attach mathematical formulas to cells. The following code shows how to attach a formula to a cell. The example assigns a formula to calculate the total value of other cells in the worksheet. Notice that, in order to create a cell with a formula, you must first set the cell type to the FORMULA type.
When the workbook is complete, you can save it to a file system by opening a FileOutputStream object for the destination file and writing the Workbook contents to the stream using the write method.
It is really as simple as that. Here’s the entire procedure in condensed form.
Reading an Excel Document
Next, create a new workbook from the input stream. You can obtain a reference to any of the worksheets within the workbook. Notice that the worksheet index starts at 0.
A Little Bit More
The following points are important:
This tutorial should help you to get started in the world of Java-to-Microsoft bridges. The POI project offers considerably more than I’ve discussed here, such as the capability to interact with Microsoft Word and with Adobe’s PDF files. The project is very active, so you should monitor the POI project and keep up what’s going on. Related ArticlesCharlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience. Related PostsAbout Our Editorial ProcessAt DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere. See our full editorial policy. ![]() What Is GPT-6.2 Astra? OpenAI’s Benchmark-Topping Model Explained
Rashan Dixon
December 1, 2026
7:21 AM
![]() What Businesses Should Consider When Selecting Perimeter Security Solutions
Steve Gickling
November 30, 2026
4:44 PM
![]() What Is Anthropic’s Messages API Rust Rewrite? AI-Verified Migration Explained
Deanna Ritchie
November 30, 2026
11:18 AM
![]() What Is Gemini 4 Neon? Google’s New Mid-Tier AI Model Explained
Steve Gickling
November 27, 2026
8:12 AM
![]() What Is AI-Assisted Vulnerability Research? Chrome 158’s Claude-Found Bugs Explained
Rashan Dixon
November 26, 2026
8:02 AM
![]() The Cheapest Ways to Run an AI Agent 24/7 in 2027 (Ranked)
John Rampton
November 25, 2026
1:52 PM
![]() What Is Java4Shell? The Critical OpenJDK Base64 Vulnerability Explained
Deanna Ritchie
November 25, 2026
8:05 AM
![]() What Is the Agent-Framework PyPI Attack? Microsoft’s Credential Stealer Explained
Steve Gickling
November 24, 2026
7:59 AM
![]() One Design System for the Product and the Marketing Site, or Two?
Rashan Dixon
November 23, 2026
3:12 PM
![]() What Is NGINX2Root? The Critical NGINX RCE Vulnerabilities Explained
Rashan Dixon
November 23, 2026
7:28 AM
![]() How Fintech Is Transforming the Way Consumers Manage Monthly Bills
Steve Gickling
November 20, 2026
11:53 AM
![]() What Is .NET 11? C# 15 Union Types and AI Tooling Explained
Deanna Ritchie
November 20, 2026
10:51 AM
![]() Just-in-Time Privileged Access Should Be Scoped to Tasks, Not People
kellybryson
November 19, 2026
2:19 PM
![]() What Is Windows 11’s Coding Agent Telemetry? Privacy Risk Explained
Steve Gickling
November 19, 2026
7:41 AM
![]() What Is the cPGuard Supply Chain Attack? OpsShield’s Backdoor Explained
Rashan Dixon
November 18, 2026
8:31 AM
![]() What Is wfx-loot? The GitHub Actions Secret Stealer Attack Explained
Deanna Ritchie
November 17, 2026
8:38 AM
![]() What Is Gemini 4 Hydrogen? Google’s Fast, Low-Cost Coding Model Explained
Steve Gickling
November 16, 2026
8:08 AM
![]() What Is GPT-6 Cyber? OpenAI’s New Cybersecurity AI Model Explained
Rashan Dixon
November 13, 2026
8:08 AM
![]() What Is Microsoft’s November 2026 Patch Tuesday? Outlook Zero-Day Explained
Deanna Ritchie
November 12, 2026
8:08 AM
![]() What Is Claude Fable 5.2? Anthropic’s New Flagship Model Explained
Steve Gickling
November 11, 2026
8:12 AM
![]() What Is DeepSeek Super-Agent? DeepSeek’s Open Source Coding Agent Explained
Rashan Dixon
November 10, 2026
7:52 AM
![]() What Is the Meta Conductor Acquisition? AI Coding Agents Explained
Deanna Ritchie
November 9, 2026
8:07 AM
![]() Exploring How Service Robots Navigate Everyday Unpredictability with LiDAR
Steve Gickling
November 6, 2026
2:33 PM
![]() What Is the Cloudflare Deno Acquisition? Explained
Editorial-team
November 6, 2026
8:18 AM
![]() What Is FlashProve? Anthropic’s New Way to Verify AI Model Identity
Rashan Dixon
November 5, 2026
10:08 AM
|

























