我正在使用 Microsoft.Office.Interop.Excel 从 C# 创建一个 Excel 工作表,但我无法按照用户想要的方式获取页脚。
1) 如何将页脚文本加粗?2)如何将页码放在页脚中?(将@"Page @[Page]" 作为文本放入是行不通的。)
可能的?不可能?
The following codes are from the SpreadsheetGear for .NET help and are compatible with Excel:
* Font codes appearing after any text or non-font codes will be ignored by SpreadsheetGear's printing engine.
1)worksheet.PageSetup.LeftFooter = "&B Bold text &B"
2)worksheet.PageSetup.CenterFooter = "Page &P"
提示 - 打开 Excel 并通过 UI 设置您需要的页脚,记录您执行的操作的宏。然后打开 VBA 编辑器。生成的 VBA 将为您提供有关如何通过 API 实现相同目标的线索。在自动化 Excel 时,此技巧可用于许多场景。
没看到提到这个;&B &I 和类似代码也可以关闭,类似于 html 代码。前任:
PageSetup.LeftHeader = "&B&IBOLDITALIC&I BOLD&B NORMAL";
给出:
粗体 粗体正常
在元级别上,您可以通过录制宏并查看它的作用来发现这类事情。例如,要进行此设置,我录制了宏并将其取出:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 30/06/2009 by bloggsj
'
'
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = "&""Arial,Bold""Page &P of &N" '<== Et. Voila!
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
End With
End Sub
录制的宏有很多垃圾,但我们可以看到(Et.Voila)Excel 是如何做到的。从这个可以弄清楚如何自己做。