Excel File Properties

The following example shows how you can read and write Excel file's Document Properties like Title, Author, Comments, etc.

Excel file properties set with GemBox.Spreadsheet for Java
Screenshot of Excel file properties set with GemBox.Spreadsheet for Java
Upload your file (Drag file here)
import com.gembox.spreadsheet.*;
import java.util.Map;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.setLicense("FREE-LIMITED-KEY");

        ExcelFile workbook = ExcelFile.load("%InputFileName%");

        // Add Sheet
        ExcelWorksheet worksheet = workbook.getWorksheets().insertEmpty(0, "Document Properties");
        workbook.getWorksheets().setActiveWorksheet(worksheet);

        int rowIndex = 0;
        // Read Built-in Document Properties
        worksheet.getCell(rowIndex++, 0).setValue("Built-in document properties");

        worksheet.getCell(rowIndex, 0).setValue("Property");
        worksheet.getCell(rowIndex++, 1).setValue("Value");

        for (Map.Entry<BuiltInDocumentProperties, String> keyValue : workbook.getDocumentProperties().getBuiltIn().entrySet()) {
            worksheet.getCell(rowIndex, 0).setValue(keyValue.getKey().toString());
            worksheet.getCell(rowIndex++, 1).setValue(keyValue.getValue());
        }

        // Read Custom Document Properties
        worksheet.getCell(++rowIndex, 0).setValue("Custom Document Properties");

        worksheet.getCell(++rowIndex, 0).setValue("Property");
        worksheet.getCell(rowIndex++, 1).setValue("Value");

        // Custom document properties are not supported in XLS
        for (Map.Entry<String, Object> keyValue : workbook.getDocumentProperties().getCustom().entrySet()) {
            worksheet.getCell(rowIndex, 0).setValue(keyValue.getKey());
            worksheet.getCell(rowIndex++, 1).setValue(keyValue.getValue().toString());
        }

        // Write/Modify Document Properties
        workbook.getDocumentProperties().setBuiltIn(BuiltInDocumentProperties.AUTHOR, "John Doe");
        workbook.getDocumentProperties().setBuiltIn(BuiltInDocumentProperties.TITLE, "Generated title");

        worksheet.getColumn(0).setWidth(192, LengthUnit.PIXEL);
        worksheet.getColumn(1).setWidth(217, LengthUnit.PIXEL);

        workbook.save("Document Properties.%OutputFileType%");
    }
}

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet for Java yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.