Document Solutions for Excel, Java Edition | Document Solutions
Features / Document Properties
In This Topic
    Document Properties
    In This Topic

    Document properties can be used to identify some useful details about a document like the author, subject, category, comments, created date, last saved time etc. DsExcel supports storing built-in and custom document properties which can be exported and viewed in Excel documents. A few built-in properties can also be exported to PDF documents like Author, Title, Subject, Comments, CreatedDate and LastSavedTime.

    Note: To know more about supported document properties in PDF, refer Support Document Properties.

    The IDocumentProperty interface represents the document property and provides following methods:

    The BuiltInDocumentPropertyCollection of IWorkbook interface is a collection of built-in properties. The built-in properties can be set by using getBuiltInDocumentProperties method and setting the value of any built-in property like Author, Subject etc.

    The CustomDocumentPropertyCollection of IWorkbook interface provides overloaded add methods and an addLinkToContent method. The overloaded Add methods can be used to create new custom document properties with string, boolean, datetime, double or integer values. The addLinkToContent method can be used to create a new document property which is linked to named cells. It provides 'name' and 'source' parameters where the 'source' is a named range. If the named range is deleted, the last value that was saved in the custom property is stored. If the named range refers to more than one cell then the value of the cell in the top left corner is used. 

    Refer to the following example code to set Author and Company (built-in properties) and add a custom document property. 

    C#
    Copy Code
    //create a new workbook
    Workbook workbook = new Workbook();
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    worksheet.getRange("A1").setValue("hello");
    
    // Add a defined name.
    workbook.getNames().add("Headings", "=Sheet1!$A$1");
    
    // Set values for built-in document properties
    workbook.getBuiltInDocumentProperties().setAuthor("Beryl");
    workbook.getBuiltInDocumentProperties().setCompany("Google");
    
    // Add a custom document property.
    IDocumentProperty property = workbook.getCustomDocumentProperties().addLinkToContent("aaa", "Headings");
    Object value = property.getValue(); // The value is "Hello".
    System.out.println(value);
    PropertyType type = property.getType(); // The Type is String.
    System.out.println(type);
        
    //save to an excel file
    workbook.save("DocumentProperties.xlsx");

    Limitations

    The following document properties are not supported in DsExcel.