Spread for WPF allows you to add headers and footers to display information at the top or bottom of each page in a worksheet. You can define scaling and alignment settings for the headers and footers, as well as apply different headers and footers to the first, odd, and even pages.
You can use the following special formatting codes for header and footer properties such as LeftHeader, CenterHeader, RightHeader, LeftFooter, CenterFooter, and RightFooter.
Format code | Description |
&L | Aligns the string to the left. |
&C | Centers the text. |
&R | Aligns the string to the right. |
&E | Prints the string with double underlining. |
&X | Prints superscripts. |
&Y | Prints subscripts. |
&B | Prints the string in bold. |
&I | Prints the string in italics. |
&U | Prints the string with an underline. |
&S | Prints the string with a strikethrough. |
&"font name" | Prints characters in the specified font. Make sure to enclose the font name in double quotation marks (" "). |
&nn | Prints characters at the specified font size. nn is a two-digit number that indicates the number of points. |
&color | Prints characters in a specified color, with the user specifying a hexadecimal color value. |
&"+" | Prints text in the Heading font of the current theme. Make sure to enclose the font name in double quotation marks (" "). |
&"-" | Prints text in the Body font of the current theme. Make sure to enclose the font name in double quotation marks (" "). |
&K xx . S nnn |
Prints text in the specified color of the current theme.
If the value you specify for the theme color or shade exceeds this limit, the closest valid value will be used. |
&D | Prints the current date. |
&T | Prints the current time. |
&F | Prints the name of the file. |
&A | Prints the sheet header names. |
&P | Prints page numbers. |
&P+number | Prints the page number plus the specified <number>. |
&P-number | Prints the page number minus the specified <number>. |
&& | Prints an ampersand (&). |
&N | Prints all page numbers in the file. |
&Z | Prints the file path. |
&G | Insert an image. Set the image files in the LeftImage , CenterImage , and RightImage properties to display the position. If you reference an image file that is contained in an assembly with a URI, use an absolute package URI. |
You can add text or images to headers and footers based on your needs using the following properties of the IPageSetup interface:
The following example code adds text and images in the page header and footer.
You can specify whether the headers and footers use the same scaling and alignment as the worksheet. Use the ScaleWithDocHeaderFooter and AlignMarginsHeaderFooter properties of the IPageSetUp interface to set the scaling and alignment settings for the page header and footer. You can set these property values to true if the header and footer should scale with the document when its size changes, or align with the margins set in the page setup options; otherwise, set them to false.
The following example code sets the scaling and alignment for the page header and footer.
You can apply different headers and footers for the odd and even pages. To apply different headers and footers on odd and even pages, set the OddAndEvenPagesHeaderFooter property of the IPageSetUp interface to true.
The following example code sets different headers and footers for odd and even pages.
You can set a unique header and footer for the first page by setting the DifferentFirstPageHeaderFooter property of the IPageSetUp interface to true.
The following example code specifies a different header and footer for the first page.