# Configure Page Header and Footer

Learn how to set a different header and footer for the first page and even pages.

## Content

In DsExcel .NET, you can use the [LeftHeader property](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IPageSetup.LeftHeader.html), [LeftFooter property](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IPageSetup.LeftFooter.html), [CenterFooter property](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IPageSetup.CenterFooter.html), [RightHeader property](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IPageSetup.RightHeader.html), [CenterHeader property](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IPageSetup.CenterHeader.html), and the [RightFooter property](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IPageSetup.RightFooter.html) of the [IPageSetup interface](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IPageSetup.html) in order to configure header and footer for a page.

```csharp
//Configure PageHeader and PageFooter
//Set header for the page
worksheet.PageSetup.LeftHeader = "&\"Arial,Italic\"LeftHeader";
worksheet.PageSetup.CenterHeader = "&P";

//Set footer graphic for the page
worksheet.PageSetup.CenterFooter = "&G";
worksheet.PageSetup.CenterFooterPicture.Filename = @"Resource\logo.png";
```

For special settings, you can also refer to the following sections in order to customize the configuration of the header and footer of your page:

* [Configure First Page](/document-solutions/dot-net-excel-api/docs/online/Features/print/ConfigurePrintSettingsviaPageSetup/ConfigurePageHeaderandFooter#configure-first-page)
* [Configure Even Page](/document-solutions/dot-net-excel-api/docs/online/Features/print/ConfigurePrintSettingsviaPageSetup/ConfigurePageHeaderandFooter#configure-even-page)
* [Set Page and Total Page Number Calculation](/document-solutions/dot-net-excel-api/docs/online/Features/print/ConfigurePrintSettingsviaPageSetup/ConfigurePageHeaderandFooter#set-page-and-total-page-number-calculation)

## Configure First Page

If you want a different header and footer in your first page, you first need to set the [DifferentFirstPageHeaderFooter property](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IPageSetup.DifferentFirstPageHeaderFooter.html) of the IPageSetup interface to true. When this is done, you can use the properties of the IPageSetup interface in order to configure the first page header and footer.

```csharp
//Set first page header and footer
worksheet.PageSetup.DifferentFirstPageHeaderFooter = true;

worksheet.PageSetup.FirstPage.CenterHeader.Text = "&T";
worksheet.PageSetup.FirstPage.RightFooter.Text = "&D";

//Set first page header and footer graphic
worksheet.PageSetup.FirstPage.LeftFooter.Text = "&G";
worksheet.PageSetup.FirstPage.LeftFooter.Picture.Filename = @"Resource\logo.png";
```

## Configure Even Page

If you want a different header and footer for all the even pages, you first need to set the [OddAndEvenPagesHeaderFooter property](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IPageSetup.OddAndEvenPagesHeaderFooter.html) to true. When this is done, you can use the properties of the IPageSetup interface in order to configure the even page header and footer.

```csharp
//Set even page header and footer
worksheet.PageSetup.OddAndEvenPagesHeaderFooter = true;

worksheet.PageSetup.EvenPage.CenterHeader.Text = "&T";
worksheet.PageSetup.EvenPage.RightFooter.Text = "&D";

//Set even page header and footer graphic
worksheet.PageSetup.EvenPage.LeftFooter.Text = "&G";
worksheet.PageSetup.EvenPage.LeftFooter.Picture.Filename = @"Resource\logo.png";
```

## Set Page and Total Page Number Calculation

DsExcel supports Addition (+) and Subtraction (-) operators for page and total page number calculations in custom page headers and footers. These operators function in all paginated outputs that respect custom headers and footers in [PageSetup](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IWorksheet.PageSetup.html) property of [IWorksheet](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IWorksheet.html) interface, such as PDFs and print to physical printers.
DsExcel supports the following formulas for page and total page number calculations:

| **Formula** | **Description** |
| ------- | ----------- |
| &P+number | Prints the page number plus the specified number. |
| &P-number | Prints the page number minus the specified number. |
| &N+number | Prints the total number of pages plus the specified number. |
| &N-number | Prints the total number of pages minus the specified number. |

> !type=note
> **Note:** “number” can be any 32-bit positive integer.

```csharp
// Create a new workbook.
var workbook = new Workbook();

// Open Excel document.
workbook.Open("PageSetup Demo.xlsx");

// Access first worksheet.
IWorksheet worksheet = workbook.Worksheets[0];

// Set page headerfooter.
/* Use &P+1 to display the page number plus one.
   Use &N+1 to display the total page number plus one. */
worksheet.PageSetup.RightHeader = "Page header example &P+1 of &N+1";
worksheet.PageSetup.RightFooter = "Page footer example &P+2 of &N+2";
worksheet.PageSetup.CustomPaperSize(8.5,6);

// Save workbook to a PDF document.
workbook.Save("ConfigHeaderFooterPageNumberCalc.pdf");
```

![](https://cdn.mescius.io/document-site-files/images/e333ad47-35da-43f9-a389-25433765f491/images/page-number-calc.png)