PPT处理控件Aspose.Slides功能演示:使用 C++ 在 PowerPoint 演示文稿中添加页眉和页脚

>>你可以点击这里下载Aspose.Slides 最新版测试体验。

用于在 PowerPoint 演示文稿中添加页眉和页脚的 C++ API

我们将使用Aspose.Slides for C++ API 在 PowerPoint 演示文稿中添加页眉和页脚。它是一个强大的 API,提供了许多用于处理 PowerPoint PPTX/PPT 文件的功能。

使用 C++ 在 PowerPoint 演示文稿中添加页眉和页脚

以下是在 PowerPoint 演示文稿中添加页眉和页脚的步骤。

  • 首先,使用Presentation 类加载 PowerPoint 文件 。
  • 使用Presentation->get_HeaderFooterManager()->SetAllFootersText(System::String text)方法设置页脚文本。
  • 通过使用Presentation->get_HeaderFooterManager()->SetAllFootersVisibility(bool isVisible)方法设置其可见性来显示页脚。
  • 使用Presentation->get_MasterNotesSlideManager()->get_MasterNotesSlide()方法访问主笔记幻灯片。
  • 循环浏览主笔记幻灯片的形状。
  • 如果形状的类型为PlaceholderType::Header,请使用IAutoShape->get_TextFrame()->set_Text(System::String value)方法设置标题文本。
  • 最后,使用 Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存演示文稿。

以下示例代码显示如何使用 C++ 在 PowerPoint 演示文稿中添加页眉和页脚。

// File pathsconst String sourceFilePath = u"SourceDirectory\Slides\Presentation2.pptx";const String outputFilePath = u"OutputDirectory\AddHeaderFooter_out.pptx";// Load the Presentation fileSharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);// Setting Footerpresentation->get_HeaderFooterManager()->SetAllFootersText(u"My Footer text");presentation->get_HeaderFooterManager()->SetAllFootersVisibility(true);// Access and Update Headerauto masterNotesSlide = presentation->get_MasterNotesSlideManager()->get_MasterNotesSlide();if (nullptr != masterNotesSlide){for (const auto& shape : System::IterateOver(masterNotesSlide->get_Shapes())){if (shape->get_Placeholder() != nullptr){if (shape->get_Placeholder()->get_Type() == PlaceholderType::Header){(System::DynamicCast<IAutoShape>(shape))->get_TextFrame()->set_Text(u"HI there new header");}}}}// Save Presentationpresentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

使用 C++ 在 Notes Master 和 Notes Slides 中管理页眉和页脚

使用 Aspose.Slides for C++,您可以轻松管理笔记母版和笔记幻灯片的页眉和页脚。以下部分介绍了如何在笔记母版和笔记幻灯片中管理页眉和页脚。

更改 Notes Master 的页眉和页脚设置

以下是更改笔记母版页眉和页脚设置的步骤。

  • 首先,使用Presentation 类加载 PowerPoint 文件 。
  • 使用Presentation->get_MasterNotesSlideManager()->get_MasterNotesSlide()方法访问主笔记幻灯片。
  • 使用IMasterNotesSlide->get_HeaderFooterManager()方法访问IMasterNotesSlideHeaderFooterManager。
  • 使用IMasterNotesSlideHeaderFooterManager对象更新页眉和页脚。
  • 最后,使用 Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存演示文稿。

以下示例代码显示了如何使用 C++ 更改笔记母版中的页眉和页脚。

// File pathsconst String sourceFilePath = u"OutputDirectory\AddHeaderFooter_out.pptx";const String outputFilePath = u"OutputDirectory\ChangeHeaderFooterNotesMaster_out.pptx";// Load the Presentation fileSharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);// Change Header and Footer settings for notes master and all notes slidesauto masterNotesSlide = presentation->get_MasterNotesSlideManager()->get_MasterNotesSlide();if (masterNotesSlide != nullptr){auto headerFooterManager = masterNotesSlide->get_HeaderFooterManager();// Make the master notes slide and all child Footer placeholders visibleheaderFooterManager->SetHeaderAndChildHeadersVisibility(true);// Make the master notes slide and all child Header placeholders visibleheaderFooterManager->SetFooterAndChildFootersVisibility(true);// Make the master notes slide and all child SlideNumber placeholders visibleheaderFooterManager->SetSlideNumberAndChildSlideNumbersVisibility(true);// Make the master notes slide and all child Date and time placeholders visibleheaderFooterManager->SetDateTimeAndChildDateTimesVisibility(true);// Set text to master notes slide and all child Header placeholdersheaderFooterManager->SetHeaderAndChildHeadersText(u"Header text");// Set text to master notes slide and all child Footer placeholdersheaderFooterManager->SetFooterAndChildFootersText(u"Footer text");// Set text to master notes slide and all child Date and time placeholdersheaderFooterManager->SetDateTimeAndChildDateTimesText(u"Date and time text");}// Save Presentationpresentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

更改备注幻灯片的页眉和页脚设置

以下是更改备注幻灯片的页眉和页脚设置的步骤。

  • 首先,使用Presentation 类加载 PowerPoint 文件 。
  • 使用Presentation->get_Slides()->idx_get(0)->get_NotesSlideManager()->get_NotesSlide()方法访问笔记幻灯片。
  • 使用INotesSlide->get_HeaderFooterManager()方法访问INotesSlideHeaderFooterManager。
  • 使用INotesSlideHeaderFooterManager对象更新页眉和页脚。
  • 最后,使用 Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存演示文稿。

以下示例代码显示了如何使用 C++ 更改注释幻灯片中的页眉和页脚。

// File pathsconst String sourceFilePath = u"OutputDirectory\ChangeHeaderFooterNotesMaster_out.pptx";const String outputFilePath = u"OutputDirectory\ChangeHeaderFooterNotesSlide_out.pptx";// Load the Presentation fileSharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);// Change Header and Footer settings for first notes slide onlyauto notesSlide = presentation->get_Slides()->idx_get(0)->get_NotesSlideManager()->get_NotesSlide();if (notesSlide != nullptr){auto headerFooterManager = notesSlide->get_HeaderFooterManager();if (!headerFooterManager->get_IsHeaderVisible()){// Make this notes slide Header placeholder visibleheaderFooterManager->SetHeaderVisibility(true);}if (!headerFooterManager->get_IsFooterVisible()){// Make this notes slide Footer placeholder visibleheaderFooterManager->SetFooterVisibility(true);}if (!headerFooterManager->get_IsSlideNumberVisible()){// Make this notes slide SlideNumber placeholder visibleheaderFooterManager->SetSlideNumberVisibility(true);}if (!headerFooterManager->get_IsDateTimeVisible()){// Make this notes slide Date-time placeholder visibleheaderFooterManager->SetDateTimeVisibility(true);}// Set text to notes slide Header placeholderheaderFooterManager->SetHeaderText(u"New header text");// Set text to notes slide Footer placeholderheaderFooterManager->SetFooterText(u"New footer text");// Set text to notes slide Date-time placeholderheaderFooterManager->SetDateTimeText(u"New date and time text");}// Save Presentationpresentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。


还想要更多吗可以点击阅读【Aspose最新资源在线文库】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年10月2日
下一篇 2021年10月2日

相关推荐

发表回复

登录后才能评论