1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Aspose.Slides使用教程:使用 C++ 访问或修改 PowerPoint 文件的属性

Aspose.Slides使用教程:使用 C++ 访问或修改 PowerPoint 文件的属性

时间:2019-11-09 14:22:28

相关推荐

Aspose.Slides使用教程:使用 C++ 访问或修改 PowerPoint 文件的属性

PowerPoint 文件包含提供有关演示文稿的附加信息的元数据或文档属性。其中包括演示文稿的标题、日期、作者等信息。在本文中,将学习如何使用 C++ 访问和修改 PowerPoint 演示文稿中的属性。

如果有需要,可以进入慧都官网下载最新版Aspose.Slides for C++

目录

用于访问和修改 PowerPoint 演示文稿属性的 C++ API

PowerPoint 演示文稿中的属性类型

使用 C++ 访问 PowerPoint 演示文稿中的内置属性

使用 C++ 修改 PowerPoint 演示文稿中的内置属性

使用 C++ 在 PowerPoint 演示文稿中添加自定义属性

在 PowerPoint 演示文稿中访问和修改自定义属性

用于访问和修改 PowerPoint 演示文稿属性的 C++ API

Aspose.Slides for C++ 是一个用于处理 PowerPoint 文件的 C++ API。它无需其他软件即可创建、阅读和更新 PowerPoint 文件。此外,API 允许访问和修改 PowerPoint 演示文稿的属性。

PowerPoint 演示文稿中的属性类型

PowerPoint 演示文稿中有两种类型的属性:内置和自定义。内置属性存储有关演示文稿的一般信息,如标题、日期等。另一方面,自定义属性以键/值对的形式存储自定义信息。以下部分介绍如何添加、访问和修改 PowerPoint 演示文稿的内置和自定义属性。

使用 C++ 访问 PowerPoint 演示文稿中的内置属性

以下是访问 PowerPoint 演示文稿中的内置属性的步骤。

首先,使用Presentation 类加载 PowerPoint 文件 。使用Presentation->get_DocumentProperties()方法访问属性。使用IDocumentProperties对象和IDocumentProperties->get_Category()、IDocumentProperties->get_Author()等方法读取各个属性。

以下示例代码显示了如何使用 C++ 访问 PowerPoint 演示文稿中的内置属性。

// File pathconst String sourceFilePath = u"SourceDirectory\Slides\SamplePresentation.pptx";// Load the presentation fileauto presentation = System::MakeObject<Presentation>(sourceFilePath);// Get reference of document propertiesSystem::SharedPtr<IDocumentProperties> documentProperties = presentation->get_DocumentProperties();// Print the property valuesSystem::Console::WriteLine(u"Category : {0}", documentProperties->get_Category());System::Console::WriteLine(u"Current Status : {0}", documentProperties->get_ContentStatus());System::Console::WriteLine(u"Creation Date : {0}", documentProperties->get_CreatedTime().ToString());System::Console::WriteLine(u"Author : {0}", documentProperties->get_Author());System::Console::WriteLine(u"Description : {0}", documentProperties->get_Comments());System::Console::WriteLine(u"KeyWords : {0}", documentProperties->get_Keywords());System::Console::WriteLine(u"Last Modified By : {0}", documentProperties->get_LastSavedBy());System::Console::WriteLine(u"Supervisor : {0}", documentProperties->get_Manager());System::Console::WriteLine(u"Modified Date : {0}", documentProperties->get_LastSavedTime().ToString());System::Console::WriteLine(u"Presentation Format : {0}", documentProperties->get_PresentationFormat());System::Console::WriteLine(u"Last Print Date : {0}", documentProperties->get_LastPrinted().ToString());System::Console::WriteLine(u"Is Shared between producers : {0}", documentProperties->get_SharedDoc());System::Console::WriteLine(u"Subject : {0}", documentProperties->get_Subject());System::Console::WriteLine(u"Title : {0}", documentProperties->get_Title());

使用 C++ 修改 PowerPoint 演示文稿中的内置属性

以下是修改 PowerPoint 演示文稿中的内置属性的步骤。

首先,使用Presentation 类加载 PowerPoint 文件 。使用Presentation->get_DocumentProperties()方法检索IDocumentProperties对象中的属性。使用IDocumentProperties对象和IDocumentProperties->set_Author(System::String value)、IDocumentProperties->set_Title(System::String value)等方法修改属性。最后,使用 Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存演示文稿。

以下示例代码显示了如何使用 C++ 修改内置 PowerPoint 属性。

// File pathsconst String sourceFilePath = u"SourceDirectory\Slides\SamplePresentation.pptx";const String outputFilePath = u"OutputDirectory\ModifyBuiltinProperties_out.pptx";// Load the presentation fileauto presentation = System::MakeObject<Presentation>(sourceFilePath);// Get reference of document propertiesSystem::SharedPtr<IDocumentProperties> documentProperties = presentation->get_DocumentProperties();// Modify the built-in propertiesdocumentProperties->set_Author(u"Aspose.Slides for C++");documentProperties->set_Title(u"Modifying Presentation Properties");documentProperties->set_Subject(u"Aspose Subject");documentProperties->set_Comments(u"Aspose Comments");documentProperties->set_Manager(u"Aspose Manager");// Save Presentationpresentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

使用 C++ 在 PowerPoint 演示文稿中添加自定义属性

以下是在 PowerPoint 演示文稿中添加自定义属性的步骤。

首先,使用Presentation 类加载 PowerPoint 文件 。使用Presentation->get_DocumentProperties()方法检索IDocumentProperties对象中的属性。使用IDocumentProperties->idx_set(System::String name, System::SharedPtrSystem::Objectvalue)方法添加自定义属性。最后,使用 Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存演示文稿。

以下示例代码显示了如何在 PowerPoint 演示文稿中添加自定义属性。

// File pathsconst String sourceFilePath = u"SourceDirectory\Slides\SamplePresentation.pptx";const String outputFilePath = u"OutputDirectory\AddCustomProperties_out.pptx";// Load the presentation fileauto presentation = System::MakeObject<Presentation>(sourceFilePath);// Get reference of document propertiesauto documentProperties = presentation->get_DocumentProperties();// Adding Custom propertiesdocumentProperties->idx_set(u"New Custom", ObjectExt::Box<int32_t>(12));documentProperties->idx_set(u"My Name", ObjectExt::Box<String>(u"Aspose"));documentProperties->idx_set(u"Custom", ObjectExt::Box<int32_t>(124));// Getting property name at particular indexString getPropertyName = documentProperties->GetCustomPropertyName(2);// Removing selected propertydocumentProperties->RemoveCustomProperty(getPropertyName);// Save Presentationpresentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

在 PowerPoint 演示文稿中访问和修改自定义属性

以下是访问和修改 PowerPoint 演示文稿中的自定义属性的步骤。

首先,使用Presentation 类加载 PowerPoint 文件 。使用Presentation->get_DocumentProperties()方法检索IDocumentProperties对象中的属性。循环遍历属性并分别使用IDocumentProperties->GetCustomPropertyName(int32_t index)和IDocumentProperties->idx_get(System::String name)方法访问每个属性的名称和值。根据要存储的值的类型,使用IDocumentProperties->SetCustomPropertyValue()方法修改所需的自定义属性。最后,使用 Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存演示文稿。

以下示例代码显示了如何使用 C++ 访问和修改 PowerPoint 演示文稿中的自定义属性。

// File pathsconst String sourceFilePath = u"SourceDirectory\Slides\SamplePresentation.pptx";const String outputFilePath = u"OutputDirectory\AccessAndModifyCustomProperties_out.pptx";// Load the presentation fileauto presentation = System::MakeObject<Presentation>(sourceFilePath);// Create a reference to DocumentProperties object associated with PresentationSystem::SharedPtr<IDocumentProperties> documentProperties = presentation->get_DocumentProperties();// Access custom propertiesfor (int32_t i = 0; i < documentProperties->get_CountOfCustomProperties(); i++){// Print the name and value of custom propertiesSystem::Console::WriteLine(u"Custom Property Name : {0}", documentProperties->GetCustomPropertyName(i));System::Console::WriteLine(u"Custom Property Value : {0}", documentProperties->idx_get(documentProperties->GetCustomPropertyName(i)));// Modify the custom propertydocumentProperties->SetCustomPropertyValue(documentProperties->GetCustomPropertyName(i), String::Format(u"Title : {0}", i));}// Save Presentationpresentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。