Excel header and footer

Every Excel worksheet can contain headers and / or footers which can be defined on the first page, even pages and all other pages on which worksheet is shown / printed.

Following example shows how to add headers and footers to the first page and to all other pages of a worksheet.

Screenshot of Excel header and footer added with GemBox.Spreadsheet for Java
Excel header and footer added with GemBox.Spreadsheet for Java
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using Professional version, put your serial key below.

        ExcelFile workbook = new ExcelFile();
        ExcelWorksheet worksheet = workbook.addWorksheet("Header and Footer");

        SheetHeaderFooter headerFooter = worksheet.getHeadersFooters();

        // Show title only on the first page
        headerFooter.getFirstPage().getHeader().getCenterSection().setContent("Title on the first page");

        // Show logo
        headerFooter.getFirstPage().getHeader().getLeftSection().appendPicture("%#Dices.png%", 40, 40);

        // "Page number" of "Number of pages"
        headerFooter.getFirstPage().getFooter().getRightSection().append("Page ").append(HeaderFooterFieldType.PAGE_NUMBER).append(" of ").append(HeaderFooterFieldType.NUMBER_OF_PAGES);

        // Fill Sheet1 with some data
        for (int i = 0; i < 140; i++)
            for (int j = 0; j < 9; j++)
                worksheet.getCell(i, j).setValue(i + j);

        workbook.save("Header and Footer.%OutputFileType%");

Check next example or download examples from GitHub.