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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:18:58  来源:igfitidea点击:

Headers for Excel worksheet using EPPlus

vb.netexcel-vbaepplusvbaexcel

提问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 FirstHeaderProperty to EvenHeaderand OddHeadersets if for the following pages.

这为首页设置。将FirstHeader属性更改为EvenHeaderOddHeader设置为以下页面。

There are a couple of properties differentFirstand differentOddEvenwhich 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.

有几个属性differentFirstdifferentOddEven如果页面有不同的标题,它们会设置。但是我无法通过将它们设置为 false 并仅设置标题之一来使其工作。必须分别设置所有三个。

Hope it is useful Thanks

希望有用 谢谢