Category: java
read Excel files
Published on 26 May 2026
Explanation
Spring Boot can read Excel files
using Apache POI library. Apache POI
helps in processing .xls and .xlsx
files.
Code:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.5</version>
</dependency>
Explanation
Upload the Excel file using MultipartFile
in a REST API.
Code:
@PostMapping("/upload")
public String readExcel(
@RequestParam("file") MultipartFile file) {
return "Excel Received";
}
Explanation
Read Excel workbook and sheet using
Apache POI.
Code:
Workbook workbook = new XSSFWorkbook( file.getInputStream()); Sheet sheet = workbook.getSheetAt(0);
Explanation
Loop through rows and cells to
read Excel data.
Code:
for (Row row : sheet) {
for (Cell cell : row) {
System.out.print(cell.toString()
+ " ");
}
System.out.println();
}
Explanation
Complete flow: Client uploads Excel file
-> Spring Boot receives MultipartFile ->
Apache POI reads workbook -> Data
is processed or stored in database.
Code:
Client --> Spring Boot API --> MultipartFile --> Apache POI --> Excel Data Processing