![]() |
VOOZH | about |
Java does not provide built-in APIs to handle Microsoft Excel files. To perform operations such as creating, reading, or updating Excel sheets, we use the Apache POI library.
Apache POI is an open-source Java library developed by the Apache Software Foundation. It allows Java programs to read, write, and manipulate Microsoft Office documents such as Excel, Word, and PowerPoint.
It supports:
To use Apache POI, you need to add the following dependencies to your project.
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.5</version>
</dependency>
</dependencies>
implementation 'org.apache.poi:poi:5.2.5'
implementation 'org.apache.poi:poi-ooxml:5.2.5'
Steps:
Example:
Output:
Steps:
Example:
You can read Excel files stored at any path using an absolute file location.
WorkbookFactory.create() can open both .xls and .xlsx files, making it more flexible than using specific XSSFWorkbook or HSSFWorkbook.
This example shows how to add new data to an already existing sheet.