Headers for Excel worksheet using EPPlus

孤人 提交于 2019-12-23 11:24:12

问题


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


回答1:


I finally figured it out.

It can be done using 
workSheet.HeaderFooter.FirstHeader.LeftAlignedText = ""
workSheet.HeaderFooter.FirstHeader.RightAlignedText = ""
workSheet.HeaderFooter.FirstHeader.CenterAlignedText = ""

This sets for the First page. Changing the FirstHeader Property to EvenHeader and OddHeader sets if for the following pages.

There are a couple of properties differentFirst and differentOddEven which set if the pages have different headers. But I was not able to get it to work By setting them to false and just setting one of the headers. Had to set all three separately.

Hope it is useful Thanks



来源:https://stackoverflow.com/questions/14489456/headers-for-excel-worksheet-using-epplus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!