Microsoft® Excel ファイルのメタデータを管理 via .NET

サーバー側 .NET API を使用して、組み込みおよびカスタム Excel ファイルのプロパティを表示、追加、更新、削除、抽出します。

 

.NET エクセル API タイトル、作成者名、ドキュメント統計などのシステム定義 (組み込み) プロパティと、名前と値のペアの形式でのユーザー定義 (カスタム) プロパティの管理をサポートします。がある ワークブッククラス ファイルをロードし、 ワークシートコレクション ワークシートのコレクションと同様に扱います ワークシートクラス 単一のワークシートを表すために使用されます。これらのクラスと併せて、BuiltInDocumentProperties、CustomDocumentProperties を使用すると、メタデータ管理のプロセスが簡素化されます。

組み込みプロパティの管理

システム定義のプロパティを管理するには、API が提供します。 組み込みドキュメントのプロパティ 、プログラマは簡単に組み込みプロパティにアクセスし、その値を更新できます。アプリケーションの要件に応じて、開発者は、 ドキュメントプロパティコレクション .

C# 組み込みプロパティを管理するコード
//Create workbook object.
Workbook wb = new Workbook();
//Access system defined document property collection.
Aspose.Cells.Properties.BuiltInDocumentPropertyCollection sdmd = wb.BuiltInDocumentProperties;
//Set the language of the Excel document.
sdmd.Language = "German, French";
//Save the workbook in xlsx format.
wb.Save(outputDir + "system-defined-properties-updated.xlsx", SaveFormat.Xlsx);
 

カスタム定義プロパティの管理

ユーザー定義プロパティを管理するには、API が提供します。 カスタムドキュメントプロパティ 、開発者は、新しいプロパティを追加するだけでなく、すでに追加されているプロパティに簡単にアクセスできます。カスタム プロパティを追加するには、 メソッドの追加CustomDocumentPropertyCollection クラスはプロパティを追加し、新しいプロパティの参照を プロパティ.DocumentProperty 物体。 DocumentProperty クラスは、ドキュメント プロパティの名前、値、タイプを取得するために使用されます。 ドキュメントプロパティ名 , DocumentProperty.Value , DocumentProperty.Type 次のいずれかを返します プロパティタイプ 列挙値。

C# Excel ファイルにメタデータを追加するコード
// string dataDir = "he path to the documents directory."
// Instantiate a Workbook object
// Open an Excel file
Workbook wkb = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.CustomDocumentPropertyCollection customProperties = wkb.Worksheets.CustomDocumentProperties;
// Adding a custom document property to the Excel file
Aspose.Cells.Properties.DocumentProperty publisher = customProperties.Add("Publisher", "Aspose");
// Add link to content.
customProperties.AddLinkToContent("Owner", "MyRange");
// way to access custom property by using the property name
Aspose.Cells.Properties.DocumentProperty customProperty1 = customProperties["Owner"];
// Saving resultant spreadsheet
wkb.Save(dataDir + "out_sample-document-properties.xlsx");
C# Excel ファイルのカスタム プロパティを削除するコード
//string dataDir = "The path to the documents directory";
// Instantiate a Workbook object
// Open an Excel file
Workbook wkb = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.DocumentPropertyCollection customProperties = wkb.Worksheets.CustomDocumentProperties;
// Removing a custom document property
customProperties.Remove("Publisher");
// Save the file
wkb.Save(dataDir + "out_sample-document-properties.xlsx");