Aspose.Slides使用教程:使用 C# 在 PowerPoint 演示文稿中添加页眉和页脚
目录
在 PowerPoint 中管理页眉和页脚的 .NET API
使用 C# 管理讲义和备注幻灯片中的页眉和页脚
更改备注幻灯片的页眉和页脚设置
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 in masterNotesSlide.Shapes){if (shape.Placeholder != null){if (shape.Placeholder.Type == PlaceholderType.Header){((IAutoShape)shape).TextFrame.Text = "HI there new header";}}}
}// Save presentation
pres.Save("HeaderFooter.pptx", SaveFormat.Pptx);
使用 C# 管理讲义和备注幻灯片中的页眉和页脚
Aspose.Slides for .NET 还允许您在讲义和注释幻灯片中设置页眉和页脚。为此,您可以在主笔记幻灯片或单个幻灯片中应用更改。以下部分涵盖了这两种情况。
更改 Notes Master 的页眉和页脚设置
- 首先,使用Presentation类创建一个新的演示文稿或加载一个现有的演示文稿。
- 然后,使用Presentation.MasterNotesSlideManager.MasterNotesSlide属性访问IMasterNotesSlide对象中的主笔记幻灯片。
- 从IMasterNotesSlide.HeaderFooterManager属性获取IMasterNotesSlideHeaderFooterManager 的引用。
- 使用IMasterNotesSlideHeaderFooterManager对象更新页眉页脚。
- 最后,使用Presentation.Save(string, SaveFormat)方法保存演示文稿。
以下代码示例展示了如何使用 C# 更改笔记母版中的页眉和页脚。
using (Presentation presentation = new Presentation("presentation.pptx"))
{// Change Header and Footer settings for notes master and all notes slidesIMasterNotesSlide masterNotesSlide = presentation.MasterNotesSlideManager.MasterNotesSlide;if (masterNotesSlide != null){IMasterNotesSlideHeaderFooterManager headerFooterManager = masterNotesSlide.HeaderFooterManager;headerFooterManager.SetHeaderAndChildHeadersVisibility(true); // make the master notes slide and all child Footer placeholders visibleheaderFooterManager.SetFooterAndChildFootersVisibility(true); // make the master notes slide and all child Header placeholders visibleheaderFooterManager.SetSlideNumberAndChildSlideNumbersVisibility(true); // make the master notes slide and all child SlideNumber placeholders visibleheaderFooterManager.SetDateTimeAndChildDateTimesVisibility(true); // make the master notes slide and all child Date and time placeholders visibleheaderFooterManager.SetHeaderAndChildHeadersText("Header text"); // set text to master notes slide and all child Header placeholdersheaderFooterManager.SetFooterAndChildFootersText("Footer text"); // set text to master notes slide and all child Footer placeholdersheaderFooterManager.SetDateTimeAndChildDateTimesText("Date and time text"); // set text to master notes slide and all child Date and time placeholders}// Save presentationpresentation.Save("testresult.pptx",SaveFormat.Pptx);
}
更改备注幻灯片的页眉和页脚设置
- 首先,使用Presentation类创建一个新的演示文稿或加载一个现有的演示文稿。
- 然后,使用Presentation.Slides[index].NotesSlideManager.NotesSlide属性访问所需幻灯片的INotesSlide对象。
- 从INotesSlide.HeaderFooterManager属性获取INotesSlideHeaderFooterManager 的引用。
- 使用INotesSlideHeaderFooterManager对象更新页眉页脚。
- 最后,使用Presentation.Save(string, SaveFormat)方法保存演示文稿。
以下代码示例展示了如何使用 C# 更改笔记幻灯片中的页眉和页脚。
// Load presentation
using (Presentation presentation = new Presentation("presentation.pptx"))
{// Change Header and Footer settings for first notes slide onlyINotesSlide notesSlide = presentation.Slides[0].NotesSlideManager.NotesSlide;if (notesSlide != null){INotesSlideHeaderFooterManager headerFooterManager = notesSlide.HeaderFooterManager;if (!headerFooterManager.IsHeaderVisible)headerFooterManager.SetHeaderVisibility(true); // make this notes slide Header placeholder visibleif (!headerFooterManager.IsFooterVisible)headerFooterManager.SetFooterVisibility(true); // make this notes slide Footer placeholder visibleif (!headerFooterManager.IsSlideNumberVisible)headerFooterManager.SetSlideNumberVisibility(true); // make this notes slide SlideNumber placeholder visibleif (!headerFooterManager.IsDateTimeVisible)headerFooterManager.SetDateTimeVisibility(true); // make this notes slide Date-time placeholder visibleheaderFooterManager.SetHeaderText("New header text"); // set text to notes slide Header placeholderheaderFooterManager.SetFooterText("New footer text"); // set text to notes slide Footer placeholderheaderFooterManager.SetDateTimeText("New date and time text"); // set text to notes slide Date-time placeholder}// Save presentationpresentation.Save("testresult.pptx",SaveFormat.Pptx);
}
Aspose.Slides使用教程:使用 C# 在 PowerPoint 演示文稿中添加页眉和页脚相关推荐
- Aspose.Slides使用教程:使用 C++ 在 PowerPoint 演示文稿中添加幻灯片切换
目录 用于在 PowerPoint 演示文稿中添加过渡的 C++ API 使用 C++ 添加幻灯片过渡 使用 C++ 添加高级幻灯片过渡 在 PowerPoint 演示文稿中设置变形过渡类型 在 Mi ...
- Aspose.Slides使用教程:使用 C++ 在 PowerPoint 演示文稿中嵌入视频
目录 用于在 PowerPoint 演示文稿中嵌入视频的 C++ API 使用 C++ 在 PowerPoint 演示文稿中嵌入视频 在 PowerPoint 演示文稿中嵌入来自 Web 源的视频 使 ...
- PPT处理控件Aspose.Slides功能演示:使用 C# 在 PowerPoint 演示文稿中创建 SmartArt
演示文稿中的 SmartArt 用于以视觉形式提供信息.有时,选择使简单的文本更具吸引力.而在其他情况下,它用于演示流程图.流程.不同实体之间的关系等.下面将介绍如何使用 C# 以编程方式在 Powe ...
- 文档处理教程:使用C#在PowerPoint演示文稿中创建图表
图表用于汇总和直观表示PowerPoint演示文稿中的数据.因此,PowerPoint提供了多种图表类型以可视化数据.其中,最常用的图表类型包括饼图,折线图,条形图,直方图,股票图等.在本文中,将学习 ...
- [教程]如何在PowerPoint演示文稿中嵌入交互式图表
在PowerPoint演示文稿中嵌入图表并不稀奇,但也许最被忽视的是直接在演示稿中嵌入网络应用. 但您知道这是可以做到的吗? 如前所述,可以说这是一个鲜为人知的功能.我们在LightningChart ...
- 如何在PowerPoint演示文稿中使用iTunes音乐
One of PowerPoint's charms is its ability to play music during the presentation. Adding music to you ...
- ppt中的流程图怎么整体移动_小金在PowerPoint演示文稿中绘制了一个包含多个图形的流程图,他希望该流程图中的所有图形可以作为一个整体移动,最优的操作方法是______...
小金在PowerPoint演示文稿中绘制了一个包含多个图形的流程图,他希望该流程图中的所有图形可以作为一个整体移动,最优的操作方法是______ 答:选择流程图中的所有图形,通过\"绘图工具 ...
- 【制作多媒体演示文稿软件】Focusky教程 | 如何在focusky演示文稿中添加音乐?
在Focusky(也称为"FS软件")演示文稿中添加音乐非常便捷,有以下两种方法: 方法一:添加本地音乐 单击工具栏上的"插入", 在下拉栏中选择"音 ...
- 将其他程序中的大纲文本插入到 PowerPoint 演示文稿中
如果要根据现有报告或其他分级显示的文档(在 Microsoft Office Word 2007 中或其他任何支持使用标题样式的程序中创建)制作演示文稿,则可以通过将文档插入到 Microsoft O ...
最新文章
- python3.6.0安装教程-Python 3.6.0下载及安装教程
- MyBatis小问题(1)-Mapper中错误No constructor found...
- 真诚推荐几个最值得关注的前端公众号
- CentOS上安装SQL Server vNext CTP1
- Mac python Tesseract 验证码识别
- 【深入Java虚拟机】之一:Java内存区域与内存溢出
- Qt仿win7自动顶部最大化左侧右侧半屏效果
- 昇腾AI计算,无惧618冲动消费
- buck变换器设计matlab_在数字控制系统中实现LLC变换器的电流模式控制的思考
- DirectX9 3D 快速上手 1
- Centos 配置eth0 提示Device does not seem to be present -- 转载
- java基础练习题及答案_java基础测试题含答案.docx
- 如何去掉广告实现百度精准搜索
- 学生图书馆系统mysql数据库设计
- Android开发之打卡功能
- [办公应用]word 2007:全屏快捷键,让复制图片保持原样大小(office 全屏快捷键)...
- diagram使用(BLOCK DIAGRAM)
- R语言大全(后续更新和优化结构)
- 林志炫-快乐老家-LRC歌词下载
- 启xin宝app的token算法破解——逆向篇(二)
热门文章
- java 自定义循环标签_Jsp2.0自定义标签(第二天)——自定义循环标签
- 浅析 ddl,dml,dql,dcl 概念定义
- 音视频通话:​Linphone基于SIP协议的语音视频电话软件
- 微信小程序-如何处理时间戳
- numpy和pandas简单使用
- unity3D 鼠标滚轮实现物体的大小缩放
- [books] - SICP 2nd edition
- uni-app公用方法
- 用微信 远程遥控 服务器
- 徒手写代码之《机器学习实战》-----决策树算法(2)(使用决策树预测隐形眼镜类型)