Headers for Excel worksheet using EPPlus

Jan 24, 2013 at 1:34 PM

I am using EPPLus to create and format an excel sheet from my data set. I want to set headers on the excel sheet using EPPlus. I could not find a way to do it. I want to set the left header, right header and center header. I have done this using VBA code, but I wan to move away from that. In VBA I would just do

With ActiveSheet.PageSetup
.LeftHeader = ""
.RightHeader =""
.CenterHeader= ""
End With

Help!! Thanks

PS: I am creating a winforms application. I was not sure if that would change anything but just wanted to mention it here. Thanks

Jan 24, 2013 at 11:59 PM
Edited Jan 25, 2013 at 12:01 AM
In visual studio after you type in a worksheet name followed by a dot symbol a pop up list should appear with a list of class members.  Scroll down and you will find 'Headerfooter'
      excel_worksheet_2.HeaderFooter.FirstHeader.CenteredText = "FirstHeader.Centered Text- This goes top of (A4 portrait) page 1 of 2 as a header centrued";       excel_worksheet_2.HeaderFooter.FirstFooter.CenteredText = "FirstFooter.Centered Text - This goes bottom of (A4 portrait) page 1 of 2 as a footer centrued";       excel_worksheet_2.HeaderFooter.EvenHeader.LeftAlignedText = "EvenHeader.Left Aligned - This goes top left of (A4 portrait) page 2 at the top";       excel_worksheet_2.HeaderFooter.differentFirst = true//Gets/sets the flag that tells Excel to display different headers and footers on the first page of the worksheet.

My experience with Excel itself is not that extensive.  I am learning it now through epplus.  I suppose other people look for a lot of things they have done with Excel to do with epplus.

From the epplus 3.1 help chm --> ExcelHeaderFooter

The ExcelHeaderFooter type exposes the following members.

Collapse imageProperties


Name Description

AlignWithMargins
Gets/sets the alignWithMargins attribute

differentFirst
Gets/sets the flag that tells Excel to display different headers and footers on the first page of the worksheet.

differentOddEven
Gets/sets the flag that tells Excel to display different headers and footers on odd and even pages.

EvenFooter
Provides access to the footer on even numbered pages of the document.

EvenHeader
Provides access to the header on even numbered pages of the document.

FirstFooter
Provides access to the footer on the first page of the document.

FirstHeader
Provides access to the header on the first page of the document.

OddFooter
Provides access to the footer on odd numbered pages of the document. If you want the same footer on both odd and even pages, then only set values in this ExcelHeaderFooterText class.

OddHeader
Provides access to the header on odd numbered pages of the document. If you want the same header on both odd and even pages, then only set values in this ExcelHeaderFooterText class.

Pictures
Vml drawings. Underlaying object for Header footer images