ドキュメント プロパティの管理

序章

Microsoft Excel には、スプレッドシート ファイルにプロパティを追加する機能があります。これらのドキュメント プロパティは有用な情報を提供し、以下に詳述するように 2 つのカテゴリに分けられます。

  • システム定義 (組み込み) プロパティ: 組み込みプロパティには、ドキュメントのタイトル、作成者名、ドキュメントの統計など、ドキュメントに関する一般的な情報が含まれています。
  • ユーザー定義 (カスタム) プロパティ: 名前と値のペアの形式でエンド ユーザーによって定義されたカスタム プロパティ。

Microsoft Excel を使用したドキュメント プロパティの管理

Microsoft Excel では、Excel ファイルのドキュメント プロパティを WYSIWYG 方式で管理できます。以下の手順に従って、プロパティ Excel 2016 のダイアログ。

  1. からファイルメニュー、選択情報.
情報メニューの選択
todo:画像_代替_文章
  1. クリックプロパティ見出しを開き、[詳細プロパティ] を選択します。
詳細プロパティの選択をクリックする
todo:画像_代替_文章
  1. ファイルのドキュメント プロパティを管理します。
プロパティダイアログ
todo:画像_代替_文章
[プロパティ] ダイアログには、[全般]、[概要]、[統計]、[コンテンツ]、[税関] などのさまざまなタブがあります。各タブは、ファイルに関連するさまざまな種類の情報を構成するのに役立ちます。 [カスタム] タブは、カスタム プロパティを管理するために使用されます。

Aspose.Cells を使用したドキュメント プロパティの操作

開発者は、Aspose.Cells API を使用してドキュメント プロパティを動的に管理できます。この機能は、開発者がファイルの受信、処理、タイムスタンプなどの有用な情報をファイルとともに保存するのに役立ちます。

ドキュメント プロパティへのアクセス

Aspose.Cells API は、組み込みとカスタムの両方のタイプのドキュメント プロパティをサポートします。 Aspose.Cells'ワークブッククラスは Excel ファイルを表し、Excel ファイルと同様に、ワークブッククラスには複数のワークシートを含めることができ、それぞれがワークシートクラスで表されますが、ワークシートのコレクションはワークシート コレクションクラス。

使用ワークシート コレクション以下で説明するように、ファイルのドキュメント プロパティにアクセスします。

両方のWorksheetCollection.BuiltInDocumentPropertiesWorksheetCollection.CustomDocumentPropertiesのインスタンスを返しますAspose.Cells.Properties.DocumentPropertyCollection.このコレクションにはAspose.Cells.Properties.DocumentProperty各オブジェクトは、単一の組み込みまたはカスタム ドキュメント プロパティを表します。

プロパティにアクセスする方法は、アプリケーションの要件次第です。のプロパティのインデックスまたは名前を使用してドキュメント プロパティ コレクション以下の例に示すように。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.DocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
// Accessing a custom document property by using the property name
Aspose.Cells.Properties.DocumentProperty customProperty1 = customProperties["ContentTypeId"];
Console.WriteLine(customProperty1.Name + " " + customProperty1.Value);
// Accessing the same custom document property by using the property index
Aspose.Cells.Properties.DocumentProperty customProperty2 = customProperties[0];
Console.WriteLine(customProperty2.Name + " " + customProperty2.Value);

Aspose.Cells.Properties.DocumentPropertyクラスを使用すると、ドキュメント プロパティの名前、値、およびタイプを取得できます。

  • プロパティ名を取得するには、次を使用しますDocumentProperty.Name.
  • プロパティ値を取得するには、次を使用しますDocumentProperty.Value. DocumentProperty.Value値をオブジェクトとして返します。
  • プロパティ タイプを取得するには、次を使用します。DocumentProperty.Type .これは、プロパティタイプ列挙値。プロパティ タイプを取得したら、次のいずれかを使用します。DocumentProperty.ToXXXを使用する代わりに、適切な型の値を取得するメソッドDocumentProperty.Value.のDocumentProperty.ToXXXメソッドについては、次の表で説明します。
メンバー名 説明 ToXXX メソッド
ブール値 プロパティのデータ型はブール値です ブール
日にち プロパティのデータ型は DateTime です。 Microsoft Excelストアのみ
日付部分。このタイプのカスタム プロパティに時刻を格納することはできません
ToDateTime
浮く プロパティのデータ型は Double です 二重にする
番号 プロパティのデータ型は Int32 です ToInt
プロパティのデータ型は文字列です ToString
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.DocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
// Accessing a custom document property
Aspose.Cells.Properties.DocumentProperty customProperty1 = customProperties[0];
// Storing the value of the document property as an object
object objectValue = customProperty1.Value;
// Accessing a custom document property
Aspose.Cells.Properties.DocumentProperty customProperty2 = customProperties[1];
// Checking the type of the document property and then storing the value of the
// document property according to that type
if (customProperty2.Type == Aspose.Cells.Properties.PropertyType.String)
{
string value = customProperty2.Value.ToString();
Console.WriteLine(customProperty2.Name + " : " + value);
}

カスタム ドキュメント プロパティの追加または削除

このトピックの冒頭で説明したように、これらのプロパティはシステム定義であるため、開発者は組み込みプロパティを追加または削除できませんが、カスタム プロパティはユーザー定義であるため、追加または削除することができます。

カスタム プロパティの追加

Aspose.Cells API が追加の方法CustomDocumentPropertyCollectionコレクションにカスタム プロパティを追加するためのクラス。の追加メソッドはプロパティを Excel ファイルに追加し、新しいドキュメント プロパティの参照をAspose.Cells.Properties.DocumentProperty物体。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.CustomDocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
// Adding a custom document property to the Excel file
Aspose.Cells.Properties.DocumentProperty publisher = customProperties.Add("Publisher", "Aspose");
// Saving resultant spreadsheet
workbook.Save(dataDir + "out_sample-document-properties.xlsx");

「コンテンツへのリンク」カスタム プロパティの構成

特定の範囲のコンテンツにリンクされたカスタム プロパティを作成するには、CustomDocumentPropertyCollection.AddLinkToContentメソッドとパスのプロパティ名とソース。を使用して、プロパティがコンテンツにリンクされているように構成されているかどうかを確認できます。DocumentProperty.IsLinkedToContent財産。さらに、以下を使用してソース範囲を取得することもできます。ソースのプロパティドキュメント プロパティクラス。

この例では、単純なテンプレート Microsoft Excel ファイルを使用します。ワークブックには、ラベルが付けられた定義済みの名前付き範囲がありますマイレンジこれはセル値を参照します。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate an object of Workbook
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.CustomDocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
// Add link to content.
customProperties.AddLinkToContent("Owner", "MyRange");
// Accessing the custom document property by using the property name
Aspose.Cells.Properties.DocumentProperty customProperty1 = customProperties["Owner"];
// Check whether the property is lined to content
bool islinkedtocontent = customProperty1.IsLinkedToContent;
// Get the source for the property
string source = customProperty1.Source;
// Save the file
workbook.Save(dataDir + "out_sample-document-properties.xlsx");

カスタム プロパティの削除

Aspose.Cells を使用してカスタム プロパティを削除するには、DocumentPropertyCollection.Removeメソッドを呼び出して、削除するドキュメント プロパティの名前を渡します。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.DocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
// Removing a custom document property
customProperties.Remove("Publisher");
// Save the file
workbook.Save(dataDir + "out_sample-document-properties.xlsx");

先行トピック