このクイックガイドでは、Java を使用して Excel でドキュメントのプロパティを表示する方法について説明します。これには、開発用に IDE を設定するためのリソース、この機能に必要な手順のリスト、Java を使用して Excel スプレッドシートのプロパティを出力するためのサンプル コードが含まれています。さまざまなドキュメントのプロパティに関する情報と、要件に応じたさまざまな方法でのアクセス方法についての情報が得られます。
Java を使用して Excel ファイルのプロパティを表示する手順
- Aspose.Cells for Java を使用して IDE を設定し、Excel ファイルのプロパティを出力します
- Excel ファイルを Workbook にロードし、カスタム プロパティ コレクションを反復処理します。
- オブジェクト タイプを DocumentProperty に変更し、名前と値を表示します
- すべての組み込みプロパティを反復処理し、名前と値を表示します。
- 名前またはインデックスを使用して個々のプロパティにアクセスし、さまざまなパラメータを表示します
これらの手順は、Java* を使用して *Excel スプレッドシートのプロパティにアクセスして表示するのに役立ちます。 Excel スプレッドシートをロードし、その中の CustomDocumentProperties と BuiltInDocumentProperties のコレクションにアクセスします。各反復で、オブジェクト タイプを DocumentProperty に変換し、名前、値、およびその他の利用可能な情報を表示します。
Java を使用して Excel ワークブックのプロパティを印刷するコード
import com.aspose.cells.*; | |
public class Main | |
{ | |
public static void main(String[] args) throws Exception // Display Excel file properties in Java | |
{ | |
// Set the licenses | |
new License().setLicense("License.lic"); | |
// Open an Excel file | |
Workbook workbook = new Workbook("Input.xlsx"); | |
for(Object obj : workbook.getCustomDocumentProperties()) | |
{ | |
DocumentProperty custProp = (DocumentProperty)obj; | |
System.out.println("Workbook Custom Property Name: " + custProp.getName() + ", Value = " + custProp.getValue()); | |
} | |
for (Object obj : workbook.getBuiltInDocumentProperties()) | |
{ | |
DocumentProperty builtInProp = (DocumentProperty)obj; | |
System.out.println("Workbook Builtin Property Name: " + builtInProp.getName() + ", Value = " + builtInProp.getValue()); | |
} | |
// Retrieve a list of all builtin document properties of the Excel file | |
DocumentPropertyCollection builtinProperties = workbook.getBuiltInDocumentProperties(); | |
DocumentProperty builtinProperty; | |
// Accessing a builtin document property by using the property name | |
builtinProperty = builtinProperties.get("Author"); | |
System.out.println(builtinProperty.getName() + " " + builtinProperty.getValue()); | |
// Accessing the same builtin document property by using the property index | |
builtinProperty = builtinProperties.get(0); | |
System.out.println(builtinProperty.getName() + " " + builtinProperty.getValue()); | |
System.out.println("Done"); | |
} | |
} |
このコードは、Java を使用して Excel でドキュメントのプロパティを表示する方法 を示しています。 DocumentProperty には表示される Name と Value が含まれていますが、ソース、ハッシュ コード、isLinkedToContent、toDateTime などの他のメソッドやプロパティを使用することもできます。Excel ファイルには、タイトル、件名など、アクセスして表示できるさまざまなプロパティがあります。 、作成者、コメント、LastSavedBy、および CreateTime。
この記事では、Excel ファイルのプロパティにアクセスして表示する方法を説明しました。 Excel ファイルにフィルターを適用する場合は、Javaを使用してExcelにフィルタを適用する方法 の記事を参照してください。