目录
在 PowerPoint 中管理页眉和页脚的 .NET API
PowerPoint 演示文稿中的页眉和页脚用于显示幻灯片编号、作者、日期等附加信息。
在 PowerPoint 中管理页眉和页脚的 .NET API
为了在 PowerPoint 演示文稿中使用页眉和页脚,我们将使用Aspose.Slides for .NET。它是一个 .NET 类库,可让您创建和操作 PowerPoint 和 OpenOffice 文档。您可以从下载部分下载 API 的 DLL 。此外,API 可以通过NuGet安装 。
PM> Install-Package Aspose.Slides.NET
使用 C# 在 PowerPoint 中添加页眉和页脚
以下是使用 C# 在 PowerPoint 演示文稿中添加页眉和页脚的步骤。
- 首先,使用Presentation类创建一个新的演示文稿或加载一个现有的演示文稿。
- 然后,使用Presentation.HeaderFooterManager.SetAllFootersText(string)方法设置页脚。
- 使用Presentation.MasterNotesSlideManager.MasterNotesSlide属性访问IMasterNotesSlide对象中的主笔记幻灯片。
- 循环遍历IMasterNotesSlide.Shapes集合中的每个形状。
- 如果IShape.Placeholder.Type是PlaceholderType.Header,则使用((IAutoShape)shape).TextFrame.Text属性设置标题的文本。
- 最后,使用Presentation.Save(string, SaveFormat)方法保存演示文稿。
以下代码示例展示了如何在 PowerPoint 演示文稿中添加页眉和页脚。
// Load Presentation
Presentation pres = new Presentation("headerTest.pptx");
// Set Footer
pres.HeaderFooterManager.SetAllFootersText("My Footer text");
pres.HeaderFooterManager.SetAllFootersVisibility(true);
// Access and Update Header
IMasterNotesSlide masterNotesSlide = pres.MasterNotesSlideManager.MasterNotesSlide;
if (null != masterNotesSlide)
{
foreach (IShape shape i