Microsoft® Excel ファイルのメタデータを管理 via Java
サーバー側 Java API を使用して、カスタムおよび組み込み Excel ファイルのプロパティを表示、追加、更新、削除、または抽出します。
Java エクセル API タイトル、作成者名、ドキュメント統計などの組み込み (システム定義) プロパティの管理と、名前と値のペアの形式でのカスタム (ユーザー定義) プロパティの管理をサポートします。がある ワークブッククラス ファイルをロードし、 ワークシートコレクション ワークシートのコレクションと同様に扱います ワークシートクラス 単一のワークシートを表すために使用されます。組み込みプロパティとカスタム プロパティにアクセスする場合、BuiltInDocumentProperties、CustomDocumentProperties を使用すると、メタデータ管理のプロセスが簡単になります。
システム定義プロパティの管理
組み込みプロパティを管理するには、API が提供します。 組み込みドキュメントのプロパティ 、プログラマは簡単に組み込みプロパティにアクセスし、その値を更新できます。アプリケーションの要件に応じて、開発者は、 ドキュメントプロパティコレクション .
Java システム定義のプロパティを管理するコード
//Create workbook object. | |
Workbook wb = new Workbook(); | |
//Access system defined document property collection. | |
BuiltInDocumentPropertyCollection sdpc = wb.getBuiltInDocumentProperties(); | |
//Set the language of the Excel file. | |
sdpc.setLanguage("German, French"); | |
//Save the workbook. | |
wb.save(outputDir + "updated-builtin-document-properties.xlsx", SaveFormat.XLSX); |
カスタム定義のメタデータの追加と削除
カスタム プロパティの処理については、API が提供します。 カスタムドキュメントプロパティ を使用すると、開発者は既存のプロパティに簡単にアクセスできるだけでなく、新しいプロパティを追加することもできます。[メソッドの追加]( https://reference.aspose.com/cells/java/com.aspose.cells/customdocumentpropertycollection#add(java.lang.String,%20boolean) ) の CustomDocumentPropertyCollection クラスはプロパティを追加し、新しいプロパティの参照を プロパティ.DocumentProperty 物体。 DocumentProperty クラスは、ドキュメント プロパティの名前、値、タイプを取得するために使用されます。 ドキュメントプロパティ名 , DocumentProperty.Value , DocumentProperty.Type 次のいずれかを返します プロパティタイプ 列挙値。
Java Excel ファイルにメタデータを追加するコード
// Instantiate a Workbook object | |
// Open an Excel file | |
Workbook wkb = new Workbook(dataDir + "sample.xlsx"); | |
// Retrieve a list of all custom document properties of the Excel file | |
CustomDocumentPropertyCollection customProperties = wkb.getWorksheets().getCustomDocumentProperties(); | |
// Adding a custom document property to the Excel file | |
DocumentProperty publisher = customProperties.add("Publisher", "Aspose"); | |
// Add link to content. | |
customProperties.addLinkToContent("Owner", "MyRange"); | |
// Accessing the custom document property by using the property name | |
DocumentProperty customProperty1 = customProperties.get("Owner"); | |
// Check whether the property is lined to content | |
Boolean islinkedtocontent = customProperty1.isLinkedToContent(); | |
// Get the source for the property | |
String source = customProperty1.getSource(); | |
// save the workbook |
Java Excel ファイルのカスタム プロパティを削除するコード
// Instantiate a Workbook object | |
// Open an Excel file | |
Workbook wkb = new Workbook(dataDir + "sample.xlsx"); | |
// Retrieve a list of all custom document properties of the Excel file | |
DocumentPropertyCollection customProperties = wkb.getWorksheets().getCustomDocumentProperties(); | |
// Removing a custom document property | |
customProperties.remove("Publisher"); |