Last active
January 27, 2024 04:29
Display Document Properties in Excel using Java. For more details: https://kb.aspose.com/cells/java/display-document-properties-in-excel-using-java/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment