Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.Cells allows you to add headers and footers to worksheets at runtime but we recommend setting headers and footers manually in a pre-designed file for printing. You can use Microsoft Excel as a GUI tool to set headers and footers to save effort and development time. Aspose.Cells can import the file and save the settings.
To add headers and footers at runtime, Aspose.Cells provides special API calls and script commands to format headers and footers.
Script commands are special commands that allow you to set header and footer formatting.
| Script Commands | Description |
|---|---|
| &P | The current page number |
| &G | A picture |
| &N | The total number of pages |
| &D | The current date |
| &T | The current time |
| &A | The worksheet name |
| &F | The file name without its path |
| &&Text | Shows &Text. For example: &&WO will be displayed as &WO |
| &"<FontName>" | Represents a font name. For example: &“Arial” |
| &"<FontName>, <FontStyle>" | Represents font name with style. For example: &“Arial,Bold” |
| &<FontSize> | Represents font size. For example: “&14abc”. But, if this command is followed by a plain number to be printed in the header, this should be separated with a space character from the font size. For example: “&14 123”. |
The PageSetup class provides two methods, SetHeader and SetFooter, used to add a header and footer to a worksheet. These methods take only two parameters:
The PageSetup class has two additional methods, SetHeaderPicture and SetFooterPicture, used to add pictures into the header and footer. These methods take the parameters:
After executing the code below and opening the file, check the header of the worksheet by:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.