Create Excel File in Java using Apache POI

Apache POI is a very useful library when it comes to reading/writing in Excel. POI stands for Poor Obfuscation Implementation, referring humorously to the fact that the file formats seemed to be deliberately obfuscated, but poorly, since they were successfully reverse-engineered. Ref

We will be using the latest version of POI libraries to create excel file.

Please go through the first part of the post Read Excel File in Java using Apache POI, which explain on how to set up the jars that we need to use.

Apache POI API

Workbook: is a high level representation of an Excel workbook. We have 2 implementations of the Workbook
HSSFWorkbook for xls files
XSSFWorkbook for xlsx files

workbook.createSheet() : creates a the sheet in the workbook.

Example : create .xls file using HSSFWorkbook

a. Create a FileOutStream instance with the location where we need to create the excel file
b. Create a HSSFWorkbook instance.
c. Using the HSSFWorkbook instance create a sheet using HSSFWorkbook.createSheet()
d. Now write the output stream into the workbook. This will create a excel file in the given location with the given file name.

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn