Articles in this section
Category / Section

How to set header and footer in the PDF/Excel/Word exported page?

5 mins read

You can set the header and footer in PDF, Excel, and Word exported documents by using the ASP.NET Web Forms following events:

  • ExportPDF for PDF.
  • ExportExcel for Excel.
  • ExportWord for Word.

 

In the ExportPDF event, properties are written under the PDFExportSettings class. To display header and footer in the exported document, the properties ShowPDFHeader and ShowPDFFooter should be set to true. The header and footer text can be set by using the PDFHeaderText and PDFFooterText properties, respectively. In addition to this, PDFHeaderDescription property helps you to set the description of the header.

 

In the ExportExcel event, properties are written under the PageSetup class. The properties, CenterHeader and CenterFooter allow you to set the header and footer in the middle of a page. Likewise, the properties, LeftHeader, LeftFooter, RightHeader, and RightFooter allow the user to set the header and footer in the left or right side of a page.

 

Note:

Header and footer are not displayed in an Excel sheet, by default.  You can enable the header and footer under the Insert tab to show them page wise and also while printing.

 

In the ExportWord event, properties are written under the WordExportSettings class. To display header and footer in the exported document, the properties ShowHeader and ShowFooter should be set to true. The header and footer text can be set by using the HeaderText and FooterText properties, respectively.

 

The following code example illustrates how to add header and footer in the PDF, Excel, and Word exported document.

C#

protected void Page_Load(object sender, EventArgs e)
{
      this.OlapClient1.OlapGrid.ExportPDF += OlapGrid_ExportPDF;
      this.OlapClient1.OlapGrid.ExportExcel += OlapGrid_ExportExcel;
      this.OlapClient1.OlapGrid.ExportWord += OlapGrid_ExportWord;
}
public void OlapGrid_ExportPDF(object sender, ExportPDFEventArgs e)
{
      e.PDFExportSettings.PDFHeaderText = "Header";
      e.PDFExportSettings.PDFFooterText = "Footer";
      e.PDFExportSettings.PDFHeaderDescription = "";
      e.PDFExportSettings.ShowPDFFooter = true;
      e.PDFExportSettings.ShowPDFHeader = true;
}
private void OlapGrid_ExportExcel(object sender, ExportExcelEventArgs e)
{
      e.PageSetup.CenterHeader = "Center Header";
      e.PageSetup.CenterFooter = "Center Footer";
      e.PageSetup.LeftFooter = "Left Footer";
      e.PageSetup.LeftHeader = "Left Header";
      e.PageSetup.RightFooter = "Right Footer";
      e.PageSetup.RightHeader = "Right Header";
}
public void OlapGrid_ExportWord(object sender, ExportWordEventArgs e)
{
      e.WordExportSettings.FooterText = "Footer";
      e.WordExportSettings.HeaderText = "Header";
      e.WordExportSettings.ShowHeader = true;
      e.WordExportSettings.ShowFooter = true;
}

 

VB

Protected Sub Page_Load(sender As Object, e As EventArgs)
    AddHandler Me.OlapClient1.OlapGrid.ExportPDF, AddressOf OlapGrid_ExportPDF
    AddHandler Me.OlapClient1.OlapGrid.ExportExcel, AddressOf OlapGrid_ExportExcel
    AddHandler Me.OlapClient1.OlapGrid.ExportWord, AddressOf OlapGrid_ExportWord
End Sub
Public Sub OlapGrid_ExportPDF(sender As Object, e As ExportPDFEventArgs)
    e.PDFExportSettings.PDFHeaderText = "Header"
    e.PDFExportSettings.PDFFooterText = "Footer"
    e.PDFExportSettings.PDFHeaderDescription = ""
    e.PDFExportSettings.ShowPDFFooter = True
    e.PDFExportSettings.ShowPDFHeader = True
End Sub
Private Sub OlapGrid_ExportExcel(sender As Object, e As ExportExcelEventArgs)
    e.PageSetup.CenterHeader = "Center Header"
    e.PageSetup.CenterFooter = "Center Footer"
    e.PageSetup.LeftFooter = "Left Footer"
    e.PageSetup.LeftHeader = "Left Header"
    e.PageSetup.RightFooter = "Right Footer"
    e.PageSetup.RightHeader = "Right Header"
End Sub
Public Sub OlapGrid_ExportWord(sender As Object, e As ExportWordEventArgs)
    e.WordExportSettings.FooterText = "Footer"
    e.WordExportSettings.HeaderText = "Header"
    e.WordExportSettings.ShowHeader = True
    e.WordExportSettings.ShowFooter = True
End Sub

 

Note:

A new version of Essential Studio for ASP.NET is available. Versions prior to the release of Essential Studio 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential Studio for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.

The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential Studio for ASP.NET. Although Syncfusion will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below.

You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied