GroupDocs.Metadata for Java provides functionality that allows working with different kinds of spreadsheet formats such as XLS, XLSX, ODS, etc. For the full list of supported document formats please refer to Supported document formats.
Detecting the exact type of a document
The following sample of code will help you to detect the exact type of a loaded spreadsheet and extract some additional file format information.
try(Metadatametadata=newMetadata(Constants.InputXls)){SpreadsheetRootPackageroot=metadata.getRootPackageGeneric();IReadOnlyList<MetadataProperty>customProperties=root.getDocumentProperties().findProperties(newContainsTagSpecification(Tags.getDocument().getBuiltIn()).not());for(MetadataPropertyproperty:customProperties){System.out.println(String.format("%s = %s",property.getName(),property.getValue()));}// Extract only content type properties if requiredfor(SpreadsheetContentTypePropertycontentTypeProperty:root.getDocumentProperties().getContentTypeProperties().toList()){System.out.println(String.format("%s, %s = %s",contentTypeProperty.getSpreadsheetPropertyType(),contentTypeProperty.getName(),contentTypeProperty.getSpreadsheetPropertyValue()));}}
As you can see the code sample uses the GroupDocs.Metadata search engine to retrieve all properties that are not marked with the BuiltIn tag. Since we call the findProperties method for a certain metadata package (instance of the SpreadsheetPackage class), the search result will contain only metadata properties that are specific for spreadsheets.
Inspecting spreadsheets
The inspection feature that is introduced in this section doesn’t work with metadata directly but extracts some useful pieces of information that can be considered as metadata under some circumstances. For example, you may want to obtain information about digital signatures associated with a spreadsheet, extract user comments from the spreadsheet content, obtain hidden sheets, etc. Please follow the example below to learn how to do that.
Updating any built-in document properties is as simple as getting them. The following code sample demonstrates how to update built-in metadata properties in a spreadsheet.
The GroupDocs.Metadata API also allows adding and updating custom metadata properties (including content type properties) in a spreadsheet. Please check the code sample below.
try(Metadatametadata=newMetadata(Constants.InputXls)){SpreadsheetRootPackageroot=metadata.getRootPackageGeneric();root.getDocumentProperties().set("customProperty1","some value");root.getDocumentProperties().set("customProperty2",7);// Set a content type propertyroot.getDocumentProperties().getContentTypeProperties().set("customContentTypeProperty","custom value");metadata.save(Constants.OutputXls);}
Updating inspection properties
When you inspect a spreadsheet GroupDocs.Metadata for Java forms a metadata package containing the extracted information. The package class also provides some basic methods that allow removing the extracted properties. The following code sample demonstrates how to remove the inspection properties in a spreadsheet.