Microsoft® Excel ドキュメント メタデータを C++ 経由で管理します
C++ アプリケーション内のカスタムおよび組み込みの Excel ドキュメント プロパティを表示、挿入、更新、削除、抽出します。
Excel のメタデータ - Excel ファイルのメタデータを表示、挿入、削除する方法。 C++ エクセルライブラリ faclitates は、作成者名、タイトル、ドキュメント統計などの組み込み/システム定義のプロパティをサポートすることで簡単に実行できます。ファイルが最後に変更または保存されたときを確認する場合などに必要になります。また、カスタム/ユーザー定義のプロパティを次の形式でサポートします。名前と値のペア。プロセスを自動化するために、ライブラリでは大規模なメタデータ Excel ファイルの作成と維持がサポートされています。 ワークブック class パス、ストリーム、および特別な FileFormatType によってワークブックを開きます。したがって、その後の処理のために適切な方法でファイルをロードしてください。以下にリストされている可能性はほとんどなく、開発者はアプリケーションの要件に応じてコードを簡単に拡張できます。
組み込みプロパティの読み取りと更新
組み込みプロパティを自動化するために、API は以下を提供します。 GetBuiltInDocumentProperties() スプレッドシートのすべての組み込みドキュメント プロパティを表す DocumentProperties コレクションを返すメソッド。すべての組み込みプロパティにアクセスした後、GetTitle()、GetSubject() などの関連メソッドを使用して関連プロパティにアクセスします。プロパティを更新するには、API に SetTitle、SetSubject、SetAuthor、SetComments などのメソッドが用意されています。 組み込みドキュメントプロパティコレクション 必要な機能に。
C++ システム定義のプロパティを読み取るコード
Aspose::Cells::Startup(); | |
//Source directory path | |
U16String dirPath = u"..\\Data\\LoadingSavingForMetadata\\"; | |
//Paths of source and output excel files | |
U16String samplePath = dirPath + u"sample-metadata-properties.xlsx"; | |
//Load the sample excel file | |
Workbook wb(samplePath); | |
//Read built-in title and subject properties | |
U16String strTitle = wb.GetBuiltInDocumentProperties().GetTitle(); | |
U16String strSubject = wb.GetBuiltInDocumentProperties().GetSubject(); | |
std::cout << "Title: " << strTitle.ToUtf8() << std::endl; | |
std::cout << "Subject: " << strSubject.ToUtf8() << std::endl; | |
Aspose::Cells::Cleanup(); |
C++ 組み込みプロパティを更新するコード
Aspose::Cells::Startup(); | |
//Source directory path | |
U16String dirPath = u"..\\Data\\LoadingSavingForMetadata\\"; | |
//Output directory path | |
U16String outPath = u"..\\Data\\Output\\"; | |
//Paths of source and output excel files | |
U16String samplePath = dirPath + u"sample-metadata-properties.xlsx"; | |
U16String outputPath = outPath + u"output-metadata-properties.xlsx"; | |
//Load the sample excel file | |
Workbook wb(samplePath); | |
//Modify built-in title and subject properties | |
U16String strTitle = u"Aspose.Cells New Title"; | |
U16String strSubject = u"Aspose.Cells New Subject"; | |
wb.GetBuiltInDocumentProperties().SetTitle(strTitle); | |
wb.GetBuiltInDocumentProperties().SetSubject(strSubject); | |
//Save the output excel file | |
wb.Save(outputPath); | |
Aspose::Cells::Cleanup(); |
カスタム定義プロパティの表示と追加
カスタム プロパティの処理については、API が提供します。 ワークブック::GetCustomDocumentProperties これは、スプレッドシートのすべてのカスタム ドキュメント プロパティ コレクションを返します。まず、このメソッドを介してカスタム プロパティにアクセスすると、開発者は関連メソッドを使用して AddIDocumentProperty、AddLinkToContentProperty などのプロパティを追加し、同様に UpdateLinkedPropertyValue、UpdateLinkedRange を使用して、それぞれコンテンツとリンク範囲にリンクするカスタム ドキュメント プロパティ値を更新できます。開発者は次の関連メソッドを使用できます。 カスタムドキュメントプロパティのコレクション .
C++ カスタム プロパティを表示するコード
Aspose::Cells::Startup(); | |
//Source directory path | |
U16String dirPath = u"..\\Data\\LoadingSavingAndConverting\\"; | |
//Paths of source and output excel files | |
U16String samplePath = dirPath + u"sample-metadata-properties.xlsx"; | |
//Load the sample excel file | |
Workbook wb(samplePath); | |
//Read the custom property | |
U16String strCustomPropName = u"MyCustom1"; | |
U16String strCustomPropValue = wb.GetCustomDocumentProperties().Get(strCustomPropName).ToString(); | |
U16String myCustom1 = u"\r\nMyCustom1: "; | |
std::cout << myCustom1.ToUtf8() << strCustomPropValue.ToUtf8() << std::endl; | |
Aspose::Cells::Cleanup(); |
C++ Excel ファイルにメタデータを追加するコード
Aspose::Cells::Startup(); | |
//Source directory path | |
U16String dirPath =u"..\\Data\\LoadingSavingAndConverting\\"; | |
//Output directory path | |
U16String outPath = u"..\\Data\\Output\\"; | |
//Paths of source and output excel files | |
U16String samplePath = dirPath + u"sample-metadata-properties.xlsx"; | |
U16String outputPath = outPath + u"output-metadata-properties.xlsx"; | |
//method 1 | |
//Load the sample excel file | |
Workbook wb(samplePath); | |
//Add a new custom property | |
U16String strCustomPropName = u"MyCustom5"; | |
U16String strCustomPropValue = u"This is my custom five."; | |
wb.GetCustomDocumentProperties().Add(strCustomPropName, strCustomPropValue); | |
//Save the output excel file | |
wb.Save(outputPath); | |
////method 2 | |
////Load the sample excel file | |
//Metadata::MetadataOptions options(Metadata::MetadataType::Document_Properties); | |
//Metadata::WorkbookMetadata meta(samplePath, options); | |
////Add a new custom property | |
//meta.GetCustomDocumentProperties().Add(strCustomPropName, strCustomPropValue); | |
////Save the output excel file | |
//meta.Save(outputPath); | |
Aspose::Cells::Cleanup(); |