[Expand]General Information
[Collapse]WinForms Controls
 [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]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Map Control
   [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]Shapes, Pictures, Charts
   [Expand]Mail Merge Overview
    Find and Replace
   [Expand]Visual Elements
    [Expand]Rows and Columns
    [Expand]Import and Export Data
    [Expand]Data Binding
    [Expand]Mail Merge
    [Expand]Formatting Cells
    [Expand]Conditional Formatting
    [Expand]Group Data
    [Expand]Filter Data
    [Expand]Pivot Tables
      How to: Print a Workbook
      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: Define a Print Area
      How to: Print Titles on a Worksheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst 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]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

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.
&G HeaderFooterCode.Picture Inserts an image.
&& HeaderFooterCode.Ampersand Inserts the ampersand character.

Currently, the SpreadsheetControl does not support formatting codes for the header or footer text.

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

Is this topic helpful?​​​​​​​