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

用于访问和修改 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::SharedPtr<System::Object> value)方法添加自定义属性。
- 最后,使用 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);
如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。
还想要更多吗可以点击阅读【Aspose最新资源在线文库】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!