Selecting Excel Sheet File

In this program we are going to select the excel sheet using java .

selecting excel sheet file


In this program we are going to select the excel sheet using java .You can create any number of  sheets and you can set selected sheet . 

The package we need to import is* ,org.apache.poi.hssf.usermodel.HSSFSheet, java.util.*  and org.apache.poi.hssf.usermodel. HSSFWorkbook.

You can create any number of sheets and give the name of the sheet. You can set default selected sheet by using setSelected (Boolean value). The sheet which you want to select setSelected(True) and pass false for rest others sheets.

You can pass cells and rows values into sheets. And also you can set it selected.

In this example we have created six sheets and given its names and we setSelected(true) for  "third sheet" and setSelected( flase) for rest. The selected sheet will displayed as shown in output of program .

 The code of the program is given below:

<%page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%page contentType="application/" %>
<%page import="*" %>
<%page import="java.util.*" %>
  HSSFWorkbook hwb = new HSSFWorkbook();
  HSSFSheet sheet1 = hwb.createSheet("new sheet");
  HSSFSheet sheet2 = hwb.createSheet("second sheet");
 HSSFSheet sheet = hwb.createSheet("third sheet");
  HSSFSheet sheet4 = hwb.createSheet("fourth sheet");
 HSSFSheet sheet5 = hwb.createSheet("third sheet");
  HSSFSheet sheet6 = hwb.createSheet("fifth sheet");
FileOutputStream fileOut = new FileOutputStream
  out.println("Your excel file has been generated");
 catch Exception ex ) {

The output of the program is given below:

Download this example.

Share on Google+Share on Google+

Selecting Excel Sheet File

Posted on: May 19, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Selecting Excel Sheet File  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image