Excel Sheet Footer

In this section, you will learn how to create footer on a sheet using Apache POI.

Ads

Excel Sheet Footer

In this section, you will learn how to create footer on a sheet using Apache POI.

In the given below example, we will create footers having different position on sheet. These footers will appear on the hardcopy(print out) . You can see this by taking print preview of the sheet.

Given below the code :

import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFHeader;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Footer;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public class XLFooter {
public static void main(String args[]) throws IOException {
Workbook wb = new HSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("new sheet");

Row row = sheet.createRow((short) 0);
// Create a cell and put a value in it.
row.createCell(0).setCellValue(
createHelper.createRichTextString("Take Print Preview to View Footers"));
Footer footer= sheet.getFooter();
footer.setRight("A Roseindia Product");
footer.setCenter("Center Footer");
footer.setLeft("Left Footer");
footer.setRight(HSSFHeader.font("Stencil-Normal", "Italic")
+ HSSFHeader.fontSize((short) 10) + "A Roseindia Product");

FileOutputStream fileOut = new FileOutputStream(
"xls/workbookFooters.xls");
wb.write(fileOut);
fileOut.close();
}
}

OUTPUT

When you take its print preview, the footers will appear like below :

Download Source Code

Advertisements

Ads
Share on Google+Share on Google+

Excel Sheet Footer

Posted on: August 11, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Excel Sheet Footer  

Post your Comment


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

Ads

 

Ads