In this program, we are going to create a new excel sheet using java .You can create any number of new excel sheets in a excel file.
To create a excel sheet we can use third party APIs
.The name of this API is POI. This API is provided by the Apache Jakarta(Jakarta POI - Java API To Access Microsoft Format Files
) Tomcat. You can download POI.jar
form Apache Jakarta Project.It is open source.
OLE 2 compound Document Format is based on files including most Microsoft office files as XLS and DOC.
The package we need to import is java.io.InputStream, org.apache.poi.hssf.usermodel.HSSFSheet
and org.apache.poi.hssf.usermodel. HSSFWorkbook.
The java.io.InputStream class is used to create file. We are creating an excel file named "newrajesh.xls". The org.apache.poi.hssf.usermodel. HSSFWorkbook class is used to create an object of HSSFWorkbook, by which we will write our new rajesh.xls file. This object allows us to modify the excel file. The org.apache.poi.hssf.usermodel.HSSFSheet is used to create an object of sheet .
The org.apache.poi.hssf.usermodel.HSSFSheet is used to create a new sheet. This class extends java.lang.Object. It is used to create a high level worksheet.
To create new sheet, we use HSSFSheet constructor
in which we pass the name of the sheet as an string argument. We can create
any number of sheets. As we are creating here six sheet as named
sheet, second sheet ,third sheet ,fourth sheet, and fifth sheet.
You have to follow the following steps to execute this example:
The code of the program is given below:
The output of the program is given below:
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: May 19, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles