[]
        
(Showing Draft Content)

Configure Page Header and Footer

In GcExcel .NET, you can use the LeftHeader property, LeftFooter propertyCenterFooter property, RightHeader property, CenterHeader property, and the RightFooter property of the IPageSetup interface in order to configure header and footer for a page.

//Configure PageHeader and PageFooter
//Set header for the page
worksheet.PageSetup.LeftHeader = "&\"Arial,Italic\"LeftHeader";
worksheet.PageSetup.CenterHeader = "&P";

//Set footer graphic for the page
worksheet.PageSetup.CenterFooter = "&G";
worksheet.PageSetup.CenterFooterPicture.Filename = @"Resource\logo.png";
            

For special settings, you can also perform the following tasks in order to customize the configuration of the header and footer of your page:

  1. Configure first page header and footer
  2. Configure even page header and footer

If you want a different header and footer in your first page, you first need to set the DifferentFirstPageHeaderFooter property of the IPageSetup interface to true. When this is done, you can use the properties of the IPageSetup interface in order to configure the first page header and footer.

//Set first page header and footer
worksheet.PageSetup.DifferentFirstPageHeaderFooter = true;

worksheet.PageSetup.FirstPage.CenterHeader.Text = "&T";
worksheet.PageSetup.FirstPage.RightFooter.Text = "&D";

//Set first page header and footer graphic
worksheet.PageSetup.FirstPage.LeftFooter.Text = "&G";
worksheet.PageSetup.FirstPage.LeftFooter.Picture.Filename = @"Resource\logo.png";

If you want a different header and footer for all the even pages, you first need to set the OddAndEvenPagesHeaderFooter property to true. When this is done, you can use the properties of the IPageSetup interface in order to configure the even page header and footer.

//Set even page header and footer
worksheet.PageSetup.OddAndEvenPagesHeaderFooter = true;

worksheet.PageSetup.EvenPage.CenterHeader.Text = "&T";
worksheet.PageSetup.EvenPage.RightFooter.Text = "&D";

//Set even page header and footer graphic
worksheet.PageSetup.EvenPage.LeftFooter.Text = "&G";
worksheet.PageSetup.EvenPage.LeftFooter.Picture.Filename = @"Resource\logo.png";