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 them manually in a pre‑designed file for printing. You can use Microsoft Excel as a GUI tool to set headers and footers, saving effort and development time. Aspose.Cells can then import the file and retain the settings.
To add headers and footers at runtime, Aspose.Cells provides special API calls and script commands to format them.
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 |
| &" |
Represents a font name. For example: &“Arial” |
| &" |
Represents a font name with style. For example: &“Arial,Bold” |
| & |
Represents font size. For example: “&14abc”. But if this command is followed by a plain number to be printed in the header, it 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.