[]
        
(Showing Draft Content)

Customize Header and Footer

SpreadJS allows users to customize the header and footer that are printed on the top or bottom of a workbook or worksheet. You can use the printInfo.pageHeaderFooter method to get or set options to print the text and format of the custom header and footer on the page.


The following types of page formats are provided by the IPageCustomHeaderFooterOptions interface to apply custom headers and footers:

  • Normal: Applies header or footer on all pages.

  • First: Applies header or footer information on the first page only. Use differentFirstPage method to enable this format.

  • Odd and even: Applies header or footer information on odd pages or even pages only. Use differentOddAndEvenPages method to enable this format.

The format priority is "first page only" > "odd and even pages" > normal.

  • If both "first page only" and "odd and even pages" formats are enabled, then the header and footer of the first page are according to the "first page only" format and the others follow the rule of "odd and even pages" format.

  • The header and footer of normal pages and the header and footer of odd pages share the same customizing data.

The following code sample applies a custom header and footer on all pages.

// Configure Workbook and Worksheet
var spread = new GC.Spread.Sheets.Workbook("ss");
var activeSheet = spread.getActiveSheet();    

var printInfo = activeSheet.printInfo();

printInfo.pageHeaderFooter({
    normal: {
        header: {
            left: "&G",
            center: "Custom Header",
            leftImage: "sampleImage.jpg"
        },
        footer: {
            center: "&P/&N"
        }
    }
});