In this Blog we will find out
- How to read xls, xlsx format Excel sheet using Apache POI API
- How to write into Excel sheet using Apache POI API
Java doesn’t provide built-in support for working with excel files so we need to rely on Open Source APIs. I came across Apache POI.
Reason I choose
- Apache POI provides stream-based processing. So memory usage is less.
- It support xlsx format as well.
I implemented this in Spring Maven based Project.
Apache POI API
- We need to implement XSSFWorkbook for xlsx format keeping interface as Workbook common.
- We need to implement HSSFWorkbook for xls format
In above code based on file extension we will implement either xls or xlsx format.
Please note that we have common interface Workbook.
Once we are done with File Type now we need to read Sheet, Row, Column or Cell.
Following code will demonstrate that
To write in Excel sheet and add some formula Logic to a Cell (Here Sum of Columns)