Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Collapse]Spreadsheet
   [Expand]Product Information
    Product Structure
    Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
   [Expand]Spreadsheet Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
    Data Grouping
   [Expand]Pivot Table Overview
   [Expand]Charting Overview
    Printing
    Events
   [Expand]Mail Merge Overview
    Protection
    Find and Replace
   [Expand]Visual Elements
    Services
   [Expand]Shortcuts
   [Collapse]Examples
    [Expand]Files
    [Expand]Workbooks
    [Expand]Worksheets
    [Expand]Rows and Columns
    [Expand]Cells
    [Expand]Formulas
    [Expand]Import and Export Data
    [Expand]Data Binding
    [Expand]Mail Merge
    [Expand]Formatting Cells
    [Expand]Conditional Formatting
    [Expand]Group Data
    [Expand]Filter Data
    [Expand]Tables
    [Expand]Pivot Tables
    [Collapse]Printing
      How to: Specify Print Settings
      How to: Show a Print Preview Form for a Document
      How to: Add Headers and Footers to a Worksheet Printout
      How to: Print Titles on a Worksheet
    [Expand]Pictures
    [Expand]Charts
    [Expand]Protection
    [Expand]Customization
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Add Headers and Footers to a Worksheet Printout

The example below demonstrates how to insert headers and footers at the top and bottom of a worksheet printout.

To define the header and footer options, use the Worksheet.HeaderFooterOptions property. It provides access to the WorksheetHeaderFooterOptions object, which allows you to specify the header or footer for the first page (WorksheetHeaderFooterOptions.FirstHeader and WorksheetHeaderFooterOptions.FirstFooter), odd-numbered pages (WorksheetHeaderFooterOptions.OddHeader and WorksheetHeaderFooterOptions.OddFooter) and even-numbered pages (WorksheetHeaderFooterOptions.EvenHeader and WorksheetHeaderFooterOptions.EvenFooter) of the printed worksheet.

Expanded Header and Footer Options

Use the properties of the WorksheetHeaderFooterOptions object to specify the following header/footer settings.

Expanded Header and Footer Codes

The SpreadsheetControl supports specific codes that enable including dynamic information into a header or footer, such as a page number, current date and time, filename, worksheet name, and so on. Note that these codes can also be obtained as constant fields of the HeaderFooterCode class.

The supported header/footer codes are listed in the table below.

Code

HeaderFooterCode member

Description

&L HeaderFooterCode.LeftSection Left aligns the characters that follow.
&C HeaderFooterCode.CenterSection Centers the characters that follow.
&R HeaderFooterCode.RightSection Right aligns the characters that follow.
&P HeaderFooterCode.PageNumber Inserts the current page number.
&N HeaderFooterCode.PageTotal Inserts the total number of pages in a workbook.
&D HeaderFooterCode.Date Inserts the current date.
&T HeaderFooterCode.Time Inserts the current time.
&Z HeaderFooterCode.WorkbookFilePath Inserts the workbook file path.
&F HeaderFooterCode.WorkbookFileName Inserts the name of a workbook file.
&A HeaderFooterCode.WorksheetName Inserts the name of a worksheet.
&& HeaderFooterCode.Ampersand Inserts the ampersand character.
Note

Currently, the SpreadsheetControl does not support formatting codes for the header or footer text. All unsupported codes will be automatically removed from the header or footer.

Expanded Example

The following example prints the workbook file name in the first page header, and inserts the current date and the page indicator in the first page footer.

The image below shows the result.

Expanded See Also

How would you rate this topic?​​​​​​​