Aspose.Slides使用教程:使用 C++ 在 PowerPoint 演示文稿中添加幻灯片切换

目录

用于在 PowerPoint 演示文稿中添加过渡的 C++ API

使用 C++ 添加幻灯片过渡

使用 C++ 添加高级幻灯片过渡

在 PowerPoint 演示文稿中设置变形过渡类型

在 Microsoft PowerPoint 中设置变形过渡

使用 C++ 在 PowerPoint 演示文稿中设置变形过渡

幻灯片切换是在从一张幻灯片导航到另一张幻灯片时显示的效果。这些增强了演示文稿的外观和感觉,并使它们更具吸引力。在某些情况下,可能需要以编程方式将幻灯片切换添加到 PowerPoint 文件。为此,本文将教您如何使用 C++ 向 PowerPoint 幻灯片添加过渡。

用于在 PowerPoint 演示文稿中添加过渡的 C++ API

Aspose.Slides for C++ 是一个用于处理 PowerPoint 文件的 C++ API。它无需安装 Microsoft PowerPoint 即可创建、阅读和更新 PowerPoint 文件。此外,该 API 允许向 PowerPoint 演示文稿添加幻灯片过渡。

使用 C++ 添加幻灯片过渡

以下是在 PowerPoint 演示文稿中添加幻灯片切换的步骤。

  • 首先,使用Presentation 类加载 PowerPoint 文件 。
  • 使用Presentation->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_Type(SlideShow::TransitionType 值)方法设置幻灯片过渡。
  • 最后,使用 Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存演示文稿。

以下示例代码演示了如何使用 C++ 向 PowerPoint 幻灯片添加过渡。

// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation.pptx";
const String outputFilePath = u"OutputDirectory\\AddTransition_out.pptx";

// Load the presentation file
auto presentation = System::MakeObject<Presentation>(sourceFilePath);

// Apply circle type transition on slide 1
presentation->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Circle);

// Apply comb type transition on slide 2
presentation->get_Slides()->idx_get(1)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Comb);

// Save Presentation
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

使用 C++ 添加高级幻灯片过渡

以下是使用 C++ 向幻灯片添加高级过渡的步骤。

  • 首先,使用Presentation 类加载 PowerPoint 文件 。
  • 使用ISlideShowTransition类设置过渡类型和其他过渡效果。
  • 最后,使用 Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存演示文稿。

以下示例代码显示了如何使用 C++ 添加高级幻灯片过渡。

// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation.pptx";
const String outputFilePath = u"OutputDirectory\\AddAdvancedTransition_out.pptx";

// Load the presentation file
auto presentation = System::MakeObject<Presentation>(sourceFilePath);

// Apply circle type transition on slide 1
presentation->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Circle);

// Set the transition time of 3 seconds
presentation->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_AdvanceOnClick(true);
presentation->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_AdvanceAfterTime(3000);

// Apply comb type transition on slide 2
presentation->get_Slides()->idx_get(1)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Comb);

// Set the transition time of 5 seconds
presentation->get_Slides()->idx_get(1)->get_SlideShowTransition()->set_AdvanceOnClick(true);
presentation->get_Slides()->idx_get(1)->get_SlideShowTransition()->set_AdvanceAfterTime(5000);

// Save Presentation
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

在 PowerPoint 演示文稿中设置变形过渡类型

在演示文稿中使用变形过渡来制作幻灯片之间的平滑过渡动画。以下部分介绍了如何在 Microsoft PowerPoint 中以及如何使用 C++ 以编程方式添加变形过渡。

在 Microsoft PowerPoint 中设置变形过渡

以下是在 Microsoft PowerPoint 中添加变形过渡的步骤。

  • 打开“过渡”选项卡。
  • 选择变形过渡类型。
  • 要选择过渡效果,请在“过渡”选项卡中选择“效果选项” 。

使用 C++ 在 PowerPoint 演示文稿中设置变形过渡

与 Microsoft PowerPoint 类似,Aspose.Slides for C++ API 提供以下变形过渡效果。

  • ByObject:将执行变形过渡,将形状视为不可分割的对象。
  • ByWord:变形转换将通过在可能的情况下逐字传输文本来执行。
  • ByChar:变形转换将通过在可能的情况下按字符传输文本来执行。

以下是使用 C++ 在 PowerPoint 演示文稿中设置变形过渡的步骤。

  • 使用Presentation 类加载 PowerPoint 文件 。
  • 将过渡类型设置为morph。
  • 使用IMorphTransition->set_MorphType(TransitionMorphType value)方法设置变形过渡效果。
  • 使用 Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存演示文稿。

以下示例代码显示了如何使用 C++ 在 PowerPoint 演示文稿中设置变形过渡。

// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation.pptx";
const String outputFilePath = u"OutputDirectory\\AddMorphTransition_out.pptx";

// Load the presentation file
auto presentation = System::MakeObject<Presentation>(sourceFilePath);

// Add morph transition
presentation->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Morph);

auto morphTransition = System::DynamicCast<Aspose::Slides::SlideShow::IMorphTransition>(presentation->get_Slides()->idx_get(0)->get_SlideShowTransition()->get_Value());
morphTransition->set_MorphType(Aspose::Slides::SlideShow::TransitionMorphType::ByWord);

// Save Presentation
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

猜你喜欢

转载自blog.csdn.net/Augenstern__zyx/article/details/120996530