Home Jsp Poi make header and footer and attache it with excel sheet.
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

make header and footer and attache it with excel sheet.

Advertisement
In this example we make header and footer and attaché it with excel sheet.

 make header and footer and attache it with excel sheet.

     

In this example we make header and footer and attaché it with excel sheet. 

Code description 
The package we need to import is java.io.*,java.util.*,org.apache.poi.hssf.usermodel.HSSFSheet,org.apache.poi.hssf.usermodel. HSSFCellStyle, org.apache.poi.hssf.usermodel.HSSFCell,org.apache.poi.hssf.usermodel.HSSFRow,org.apache.hssf.util. Region
, org.apache. poi.hssf.usermodel.HSSFFooter and org.apache.poi.hssf.usermodel. HSSFWorkbook.

The org.apache. poi.hssf.usermodel.HSSFFooter  class is used to create the header and footer. We create the object of header and footer and page it on sheet. 
The method used in this example shift row

getFooter():
This method is used to gets the user model for the document footer.

getHeader()
his method is used to gets the user model for the document header.

setRight():
This method is used to set string (e.g.Header and Footer) right. 

page()::
This method returns the the  page .

numPage():
This method is used to return number of page.

In this example we are craeting the sheet and set the header and footer .The header and footer can display you on page at the time of taking print out.So we are not giving any output here. But you can download the code and check the output.

 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.HSSFRow"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFCellStyle"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFFooter"%>
<%page import="org.apache.poi.hssf.util.Region"%>
<%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");
 HSSFFooter footer = sheet.getFooter();
 footer.setRight"Page " + HSSFFooter.page() 
" of " + HSSFFooter.numPages() );
 for(int i=0;i<20;i++)
 {
  HSSFRow row = sheet.createRow((short1+i);
  HSSFCell cell = row.createCell((short1);
  cell.setCellValue("rajesh");
  }
 FileOutputStream fileOut = new FileOutputStream
(
"c:\\excel\\footerExcel.xls");
  hwb.write(fileOut);
  fileOut.close();
    out.println("Your excel file has been generated");
  catch Exception ex ) {
 }
%>

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: February 25, 2008

Ask Questions?    Discuss: make header and footer and attache it with excel sheet.   View All Comments

Post your Comment


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