動畫是 Microsoft PowerPoint 提供的一項功能,可使演示文稿更具吸引力和樂趣。它還可以用來突出幻燈片上的不同元素以引起觀眾的注意。您可以將動畫添加到幻燈片上的文本、形狀和其他元素。在本文中,您將學習如何使用 C++ 將動畫應用於 PowerPoint 文件中的文本。

用於將動畫應用於 PowerPoint 文件中的文本的 C++ API

我們將使用 Aspose.Slides for C++ API 在 PowerPoint 文件中應用文本動畫。它是一個功能強大且功能豐富的 API,無需安裝 Microsoft PowerPoint 即可創建、讀取和修改 PowerPoint PPTX/PPT 文件。您可以通過 NuGet 安裝 API 或直接從 下載 部分下載。

PM> Install-Package Aspose.Slides.Cpp

使用 C++ 將動畫應用於 PowerPoint 文件中的文本

Aspose.Slides for C++支持超過150+種動畫效果,如Expand、Fade、Blink、Zoom等。此外,它還提供了特定的動畫效果,如OLEObjectShow和OLEObjectOpen。您可以在 EffectType 枚舉中查看支持的動畫效果的完整列表。

要將動畫應用於 PowerPoint 演示文稿中的文本,請按照以下步驟操作。

以下示例代碼演示如何使用 C++ 將動畫效果應用於 PowerPoint 演示文稿中的文本。

// 文件路徑
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation2.pptx";
const String outputFilePath = u"OutputDirectory\\ApplyTextAnimation.pptx";

// 加載演示文稿文件
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);

// 訪問形狀
SharedPtr<IAutoShape> autoShape = System::DynamicCast_noexcept<Aspose::Slides::IAutoShape>(presentation->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0));

// 訪問段落
auto paragraph = autoShape->get_TextFrame()->get_Paragraphs()->idx_get(0);

// 添加效果
auto effect = presentation->get_Slides()->idx_get(0)->get_Timeline()->get_MainSequence()->AddEffect(paragraph, EffectType::Fly, EffectSubtype::Left, EffectTriggerType::OnClick);

// 保存演示文件
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

使用 C++ 從 PowerPoint 文件獲取動畫效果

您可以按照以下步驟檢索已應用於文本的動畫效果。

下面的示例代碼演示瞭如何使用 C++ 從 PowerPoint 演示文稿中的文本獲取動畫效果。

// 文件路徑
const String sourceFilePath = u"OutputDirectory\\ApplyTextAnimation.pptx";

// 加載演示文稿文件
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);

// 獲取序列
auto sequence = presentation->get_Slides()->idx_get(0)->get_Timeline()->get_MainSequence();

// 訪問形狀
SharedPtr<IAutoShape> autoShape = System::DynamicCast_noexcept<Aspose::Slides::IAutoShape>(presentation->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0));

// 循環段落
for (SharedPtr<IParagraph> paragraph : autoShape->get_TextFrame()->get_Paragraphs())
{
	// 獲得效果
	auto effects = sequence->GetEffectsByParagraph(paragraph);
	if (effects->get_Length() > 0)
	{
		// 打印到控制台
		Console::WriteLine(String::Format(u"Paragraph {0} has {1} effect.", paragraph->get_Text(), effects->idx_get(0)->get_Type()));
	}
}

獲得免費許可證

為了在沒有評估限制的情況下試用 API,您可以申請免費的臨時許可證

結論

在本文中,您了解瞭如何使用 C++ 向 PowerPoint 演示文稿中的文本添加動畫效果。此外,您還了解瞭如何從 PowerPoint 演示文稿中的文本中檢索動畫效果。 Aspose.Slides for C++ 提供了許多附加功能,您可以通過訪問官方文檔 詳細了解這些功能。如有任何疑問,請隨時通過我們的免費支持論壇與我們聯繫。

也可以看看