vba 使用 EPPlus 的 Excel 工作表标题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14489456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Headers for Excel worksheet using EPPlus
提问by Ron
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
我正在使用 EPPLus 从我的数据集中创建和格式化 Excel 工作表。我想使用 EPPlus 在 Excel 工作表上设置标题。我找不到办法做到这一点。我想设置左标题,右标题和中心标题。我已经使用 VBA 代码完成了这项工作,但我不想这样做。在 VBA 中,我只会做
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
PS:我正在创建一个 winforms 应用程序。我不确定这是否会改变任何事情,但只是想在这里提一下。谢谢
回答by Ron
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.
这为首页设置。将FirstHeader
属性更改为EvenHeader
和OddHeader
设置为以下页面。
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.
有几个属性differentFirst
,differentOddEven
如果页面有不同的标题,它们会设置。但是我无法通过将它们设置为 false 并仅设置标题之一来使其工作。必须分别设置所有三个。
Hope it is useful Thanks
希望有用 谢谢