**Headers and Footers of printed worksheets are set via the `ExcelWorksheet.HeaderFooter` property.**

### Set a header

If you want the same header on all pages when printing the worksheet, use the `ExcelWorksheet.HeaderFooter.OddHeader` property only.

```csharp
using(var package = new ExcelPackage())
{
   var sheet = package.Workbook.Worksheets.Add("Sheet1");
   // add a logo to upper left corner
   using(var fs = new FileStream(@"c:\images\myLogo.jpg", FileMode.Open))
   {
      var drawing = sheet.HeaderFooter.OddHeader.InsertPicture(fs, ePictureType.Jpg, PictureAlignment.Left);
      // you can use the drawing instance to change Height, Width, etc.
   }
   // add todays date to the upper right corner
   sheet.HeaderFooter.OddHeader.RightAlignedText = ExcelHeaderFooter.CurrentDate;
}
```

```vbnet
Using package As New ExcelPackage()
    Dim sheet = package.Workbook.Worksheets.Add("Sheet1")
    ' add a logo to upper left corner
    Using fs As New FileStream("c:\images\myLogo.jpg", FileMode.Open)
        Dim drawing = sheet.HeaderFooter.OddHeader.InsertPicture(fs, ePictureType.Jpg, PictureAlignment.Left)
        ' you can use the drawing instance to change Height, Width, etc.
    End Using
    ' add todays date to the upper right corner
    sheet.HeaderFooter.OddHeader.RightAlignedText = ExcelHeaderFooter.CurrentDate
End Using
```

### OddHeader and EvenHeader

When setting values both `ExcelWorksheet.HeaderFooter.OddHeader` and `ExcelWorksheet.HeaderFooter.EvenHeader` these will be used on every second page respectively, starting with OddHeader. See example below

```csharp
// for odd page numbers - add an image in the upper left corner
using var fs1 = new FileStream(imgPath1, FileMode.Open);
sheet.HeaderFooter.OddHeader.InsertPicture(fs1, ePictureType.Jpg, PictureAlignment.Left);

// for even page numbers - add an image in the upper right corner
using var fs2 = new FileStream(imgPath2, FileMode.Open);
sheet.HeaderFooter.EvenHeader.InsertPicture(fs2, ePictureType.Jpg, PictureAlignment.Right);


sheet.HeaderFooter.OddHeader.RightAlignedText = ExcelHeaderFooter.CurrentDate;
sheet.HeaderFooter.EvenHeader.LeftAlignedText = ExcelHeaderFooter.CurrentDate;
```

```vbnet
' for odd page numbers - add an image in the upper left corner
Using fs1 As New FileStream(imgPath1, FileMode.Open)
    ' for even page numbers - add an image in the upper right corner
    Using fs2 As New FileStream(imgPath2, FileMode.Open)
        sheet.HeaderFooter.OddHeader.InsertPicture(fs1, ePictureType.Jpg, PictureAlignment.Left)
        sheet.HeaderFooter.EvenHeader.InsertPicture(fs2, ePictureType.Jpg, PictureAlignment.Right)


        sheet.HeaderFooter.OddHeader.RightAlignedText = ExcelHeaderFooter.CurrentDate
        sheet.HeaderFooter.EvenHeader.LeftAlignedText = ExcelHeaderFooter.CurrentDate
    End Using
End Using
```

### Insert auto text

As demonstrated in the examples above you can insert various values by using static constants from the `ExcelHeaderFooter` class. See table below:

| Field | Description |
| :--- | :--- |
| `PageNumber` | Page number of the current printed page |
| `NumberOfPages` | Total number of printed pages |
| `FontColor` | Text font color |
| `SheetName` | The name of the printed worksheet |
| `FilePath` | File path of the workbook |
| `FileName` | File name of the workbook |
| `CurrentDate` | The current date |
| `CurrentTime` | The current time |
| `Image` | Background image of the printed sheet |
| `OutlineStyle` | Outline style |
| `ShadowStyle` | Shadow style |

### Footers

Works as headers (see above), but use `ExcelWorksheet.HeaderFooter.OddFooter` and `ExcelWorksheet.HeaderFooter.EvenFooter` instead.

### Using the `ExcelHeaderFooterTextCollection`

As of EPPlus 8.1 you can now handle HeaderFooter text as a list of objects with properties just like Rich text. This is an addition to the current system and is compatible with the current way you work with Headers and Footers in EPPlus.

The HeaderFooter object in the worksheet now has 3 new properties, `LeftAligned`, `Centered` and `RightAligned`. Each contains a collection of `ExcelHeaderFooterTextItems` that contains the text and it's properties. You can also add or insert pictures, page numbers, dates and so on using the collection.

Example how to add a footer with text and page number:

```csharp
worksheet.HeaderFooter.OddFooter.LeftAligned.AddText("Page: ");
worksheet.HeaderFooter.OddFooter.LeftAligned.AddPageNumber();
```

```vbnet
worksheet.HeaderFooter.OddFooter.LeftAligned.AddText("Page: ")
worksheet.HeaderFooter.OddFooter.LeftAligned.AddPageNumber()
```

Example how to change font and size:

```csharp
var text = worksheet.HeaderFooter.OddHeader.RightAligned.AddText("My Document");
text.FontSize = 24;
text.FontName = "Arial";
```

```vbnet
Dim text = worksheet.HeaderFooter.OddHeader.RightAligned.AddText("My Document")
text.FontSize = 24
text.FontName = "Arial"
```

Example how to insert a picture using a FileInfo:

```csharp
FileInfo myPicture = new FileInfo("myPicture.png");
var text = worksheet.HeaderFooter.OddHeader.RightAligned.AddPicture(myPicture);
```

```vbnet
Dim myPicture As New FileInfo("myPicture.png")
Dim text = worksheet.HeaderFooter.OddHeader.RightAligned.AddPicture(myPicture)
```

### See also

- [Sample 1.1-C\#](<https://github.com/EPPlusSoftware/EPPlus.Samples.CSharp/blob/master/01-Workbook worksheet and ranges/01-Create a simple workbook/GettingStartedSample.cs>) and [sample 1.1-VB](<https://github.com/EPPlusSoftware/EPPlus.Samples.VB/blob/master/01-Workbook worksheet and ranges/01-Create a simple workbook/GettingStartedSample.vb>) has more examples on how to add headers/footers.
