how to create excel page using jsp
In this program, we are going to create an excel using java .By going through the steps of this example we can create any number of excel pages.
To make an excel page we can use third party POI APIs. 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.
The POI project consists APIs for manipulating various file formats based on Microsoft, OLE 2 compound Document format using pure word files using Java. We can create, read or write MS Excel file using POI.
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
The java.io.InputStream class is used to create file. We are creating an excel file named "rajesh.xls " The org.apache.poi.hssf.usermodel.HSSFWorkbook class is used to create an object of HSSFWorkbook, by which we will write our rajesh.xls file. This object allow us to modify the excel file.
HSSFWorkbook class extends java.lang.Object.
HSSFWorkbook class is a high level representation of a workbook.You must create
the object of HSSFBook to read and write a workbook. It is top most class for
creating new excel sheets ,doc sheets etc.
You have to follow the following step to execute this example:
- Download the POI.jar from Apache Jakarta Project .
- Extract it and then copy poi-2.5.1-final-20040804.jar,poi-contrib-2.5.1-final-20040804.jar and poi-scratchpad-2.5.1-final-20040804.jar into C:\apache-tomcat-5.5.23\common\lib directory .
- Then download our example copy it into C:\apache-tomcat-5.5.23\webapps\excel.
- Start the web server.
- Create folder into C drive with the name of C:\excel.
- To compile and run open Internet Explore and write http://localhost:8080/excel/excelPoi.jsp.
- After pressing enter or on click Go. Output "Your file has been created succesfully" will be diplay on browser
- The excel file will be generated into C:\excel folder.
The code of the program is given below:
The output of the program is given below: