Headers and Footers on Excel Sheet Using JExcel APIs.
Previous | Home | Next |
In this tutorial we will be learning how to add Headers and Footers on Excel Sheet Using JExcel APIs.
In this section we be learning how can we set headers and Footers on Excel Sheet Using JExcel APIs. For adding the same we have to import the jxl.HeaderFooter class. The HeaderFooter class has the following constructors,
HeaderFooter()
This is the default constructor.
HeaderFooter(HeaderFooter hf)
This is a the copy constructor used while copying the sheets.
HeaderFooter(java.lang.String s)
This constructor is used when reading workbooks to separate the left, right a central part of the strings into their respective parts.
For creating headers and footers in an excel sheet using the JExcel API, we can use the setHeader() and setFooter() method defined in the jxl.SheetSettings class. The following code snippet will guide you, how to set headers and footers in an excel sheet.
WritableWorkbook workbook=Workbook.createWorkbook(new File("F:/JAVA PROJECTS/Jexcel/src/r4r/co/in/firstsheet.xls")); //create a workbook
WritableSheet sheet=workbook.createSheet("mysheet", 0); // create a sheet
sheet.getSettings().setHeader(new jxl.HeaderFooter("This is a header")); // setting a header using the Sheetsettings class
Label l=new Label(7,7,"Label"); // creating a label
sheet.addCell(l); // adding the sheet to the cell
sheet.getSettings().setFooter(new jxl.HeaderFooter("This is a footer")); // setting the footer to the sheet
Previous | Home | Next |