栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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 path
const String sourceFilePath = u"SourceDirectorySlidesSamplePresentation.pptx";

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

// Get reference of document properties
System::SharedPtr documentProperties = presentation->get_documentProperties();

// Print the property values
System::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 paths
const String sourceFilePath = u"SourceDirectorySlidesSamplePresentation.pptx";
const String outputFilePath = u"OutputDirectoryModifyBuiltinProperties_out.pptx";

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

// Get reference of document properties
System::SharedPtr documentProperties = presentation->get_documentProperties();

// Modify the built-in properties
documentProperties->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 Presentation
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

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

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

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

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

// File paths
const String sourceFilePath = u"SourceDirectorySlidesSamplePresentation.pptx";
const String outputFilePath = u"OutputDirectoryAddCustomProperties_out.pptx";

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

// Get reference of document properties
auto documentProperties = presentation->get_documentProperties();

// Adding Custom properties
documentProperties->idx_set(u"New Custom", ObjectExt::Box(12));
documentProperties->idx_set(u"My Name", ObjectExt::Box(u"Aspose"));
documentProperties->idx_set(u"Custom", ObjectExt::Box(124));

// Getting property name at particular index
String getPropertyName = documentProperties->GetCustomPropertyName(2);

// Removing selected property
documentProperties->RemoveCustomProperty(getPropertyName);

// Save Presentation
presentation->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 paths
const String sourceFilePath = u"SourceDirectorySlidesSamplePresentation.pptx";
const String outputFilePath = u"OutputDirectoryAccessAndModifyCustomProperties_out.pptx";

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

// Create a reference to documentProperties object associated with Presentation
System::SharedPtr documentProperties = presentation->get_documentProperties();

// Access custom properties
for (int32_t i = 0; i < documentProperties->get_CountOfCustomProperties(); i++)
{
// Print the name and value of custom properties
System::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 property
documentProperties->SetCustomPropertyValue(documentProperties->GetCustomPropertyName(i), String::Format(u"Title : {0}", i));
}

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/396189.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号