C++を使用してPowerPointファイルのプロパティにアクセスまたは変更する

PowerPointファイルには、プレゼンテーションに関する追加情報を提供するメタデータまたはドキュメントプロパティが含まれています。これらには、プレゼンテーションのタイトル、日付、作成者などの情報が含まれます。この記事では、C++を使用してPowerPointプレゼンテーションのプロパティにアクセスして変更する方法を学習します。

PowerPointプレゼンテーションのプロパティにアクセスして変更するためのC++API

Aspose.Slides for C++は、PowerPointファイルを操作するためのC++APIです。追加のソフトウェアを必要とせずに、PowerPointファイルを作成、読み取り、更新できます。さらに、APIを使用すると、PowerPointプレゼンテーションのプロパティにアクセスして変更できます。 APIは、NuGetからインストールするか、ダウンロードセクションから直接ダウンロードできます。

PM> Install-Package Aspose.Slides.Cpp

PowerPointプレゼンテーションのプロパティの種類

PowerPointプレゼンテーションには、組み込みとカスタムの2種類のプロパティがあります。組み込みのプロパティには、タイトル、日付などのプレゼンテーションに関する一般的な情報が格納されます。一方、カスタムプロパティには、キーと値のペアでカスタム情報が格納されます。次のセクションでは、PowerPointプレゼンテーションの組み込みプロパティとカスタムプロパティを追加、アクセス、および変更する方法について説明します。

C++を使用してPowerPointプレゼンテーションの組み込みプロパティにアクセスする

以下は、PowerPointプレゼンテーションの組み込みプロパティにアクセスするための手順です。

次のサンプルコードは、C++を使用してPowerPointプレゼンテーションの組み込みプロパティにアクセスする方法を示しています。

// ファイルパス
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation.pptx";

// プレゼンテーションファイルをロードする
auto presentation = System::MakeObject<Presentation>(sourceFilePath);

// ドキュメントプロパティの参照を取得する
System::SharedPtr<IDocumentProperties> documentProperties = presentation->get_DocumentProperties();

// プロパティ値を出力します
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プレゼンテーションの組み込みプロパティを変更する手順です。

次のサンプルコードは、C++を使用して組み込みのPowerPointプロパティを変更する方法を示しています。

// ファイルパス
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation.pptx";
const String outputFilePath = u"OutputDirectory\\ModifyBuiltinProperties_out.pptx";

// プレゼンテーションファイルをロードする
auto presentation = System::MakeObject<Presentation>(sourceFilePath);

// ドキュメントプロパティの参照を取得する
System::SharedPtr<IDocumentProperties> documentProperties = presentation->get_DocumentProperties();

// 組み込みプロパティを変更します
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");

// プレゼンテーションを保存
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

C++を使用してPowerPointプレゼンテーションにカスタムプロパティを追加する

以下は、PowerPointプレゼンテーションにカスタムプロパティを追加する手順です。

次のサンプルコードは、PowerPointプレゼンテーションにカスタムプロパティを追加する方法を示しています。

// ファイルパス
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation.pptx";
const String outputFilePath = u"OutputDirectory\\AddCustomProperties_out.pptx";

// プレゼンテーションファイルをロードする
auto presentation = System::MakeObject<Presentation>(sourceFilePath);

// ドキュメントプロパティの参照を取得する
auto documentProperties = presentation->get_DocumentProperties();

// カスタムプロパティの追加
documentProperties->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));

// 特定のインデックスでプロパティ名を取得する
String getPropertyName = documentProperties->GetCustomPropertyName(2);

// 選択したプロパティを削除する
documentProperties->RemoveCustomProperty(getPropertyName);

// プレゼンテーションを保存
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

PowerPointプレゼンテーションのカスタムプロパティへのアクセスと変更

以下は、PowerPointプレゼンテーションのカスタムプロパティにアクセスして変更する手順です。

次のサンプルコードは、C++を使用してPowerPointプレゼンテーションのカスタムプロパティにアクセスして変更する方法を示しています。

// ファイルパス
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation.pptx";
const String outputFilePath = u"OutputDirectory\\AccessAndModifyCustomProperties_out.pptx";

// プレゼンテーションファイルをロードする
auto presentation = System::MakeObject<Presentation>(sourceFilePath);

// プレゼンテーションに関連付けられたDocumentPropertiesオブジェクトへの参照を作成します
System::SharedPtr<IDocumentProperties> documentProperties = presentation->get_DocumentProperties();

// カスタムプロパティにアクセスする
for (int32_t i = 0; i < documentProperties->get_CountOfCustomProperties(); i++)
{
	// カスタムプロパティの名前と値を出力します
	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)));

	// カスタムプロパティを変更する
	documentProperties->SetCustomPropertyValue(documentProperties->GetCustomPropertyName(i), String::Format(u"Title : {0}", i));
}

// プレゼンテーションを保存
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

無料ライセンスを取得する

評価制限なしでAPIを試すために、無料の一時ライセンスをリクエストできます。

結論

この記事では、PowerPointプレゼンテーションの組み込みプロパティにアクセスして変更する方法を学習しました。さらに、Aspose.Slides for C++ APIを使用して、カスタムPowerPointプロパティを追加、アクセス、および変更する方法を見てきました。これは、PowerPoint関連のタスクを自動化するための多くの追加機能を備えた堅牢なAPIです。 公式ドキュメントにアクセスすると、APIの詳細を調べることができます。ご不明な点がございましたら、無料サポートフォーラムまでお気軽にお問い合わせください。

関連項目