Home Jsp Poi Fit Hight Ad Wdth of Ecel Seet Uing JSP
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Fit Hight Ad Wdth of Ecel Seet Uing JSP

Advertisement
In this program we are going to create a sheet after that set the values into it's cell and set the height and width.

fit height and width of excel sheet using jsp

     

In this program we are going to create a sheet after that set the values into it's cell and set the height and width. 

Code description 

The package we need to import is java.io.*,java.util.* ,org.apache.poi.hssf.usermodel.HSSFSheet, org.apache.poi.hssf.usermodel. HSSFPrintSetup, org.apache.poi.hssf.usermodel.HSSFRow, org.apache.poi.hssf.usermodel.HSSFCell org.apache. poi.hssf.usermodel. HSSFSimpleShape and org.apache.poi.hssf.usermodel. HSSFWorkbook.
 
The method used in this example:
setFitHeight(short height):
This method is used to fit the height of the sheet.The return type is void.

setFitWidth(short width) :
This method is used to fit the width of the sheet .The return type o f this method is also void.

In this example we are creating a sheet then we create the new font and add the font into workbook's object after that we create an object of print setup then set cells values and finally set the fit height and width.   
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 import="org.apache.poi.hssf.usermodel.HSSFPrintSetup"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%page contentType="application/vnd.ms-excel" %>
<%page import="java.io.*" %>
<%page import="java.util.*" %>
<%
try{
  HSSFWorkbook hwb = new HSSFWorkbook();
  HSSFSheet sheet = hwb.createSheet("new sheet");
  HSSFRow row = sheet.createRow((short)1);
  HSSFCell cell = row.createCell((short)1);
  cell.setCellValue(111111);  
  HSSFPrintSetup ps = sheet.getPrintSetup();
  sheet.setAutobreaks(true);
  ps.setFitHeight((short)1);
  ps.setFitWidth((short)1);
FileOutputStream fileOut = new FileOutputStream
(
"c:\\excel\\fitSheetOnPage.xls");
  hwb.write(fileOut);
  fileOut.close();  
  out.println("Your excel file has been generated");  
  catch Exception ex ) {  
  }%>

The output of the program is given below:

Download this example.

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 19, 2007

Ask Questions?    Discuss: Fit Hight Ad Wdth of Ecel Seet Uing JSP  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com