Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Specify Document Properties

  • 3 minutes to read

The document properties are metadata associated and stored with a workbook. To specify the standard document properties (such as DocumentProperties.Title, DocumentProperties.Author, DocumentProperties.Subject, DocumentProperties.Description etc.), use the IWorkbook.DocumentProperties property, which provides access to the DocumentProperties object, containing basic information about a workbook. Note that some of these properties are updated automatically when a document is created (DocumentProperties.Author, DocumentProperties.Created), last modified and saved (DocumentProperties.LastModifiedBy, DocumentProperties.Modified), or printed (DocumentProperties.Printed).

You can also create your own custom document properties by using the DocumentProperties.Custom property.

#Built-In Properties

The example below demonstrates how to specify the standard document properties for a workbook using the DocumentProperties property of a workbook accessible using the SpreadsheetControl.Document property.

View Example

' Set the built-in document properties.
workbook.DocumentProperties.Title = "Spreadsheet API: document properties example"
workbook.DocumentProperties.Description = "How to manage document properties using the Spreadsheet API"
workbook.DocumentProperties.Keywords = "Spreadsheet, API, properties, OLEProps"
workbook.DocumentProperties.Company = "Developer Express Inc."

' Display the specified built-in properties in a worksheet.
worksheet("B3").Value = "Title"
worksheet("C3").Value = workbook.DocumentProperties.Title
worksheet("B4").Value = "Description"
worksheet("C4").Value = workbook.DocumentProperties.Description
worksheet("B5").Value = "Keywords"
worksheet("C5").Value = workbook.DocumentProperties.Keywords
worksheet("B6").Value = "Company"
worksheet("C6").Value = workbook.DocumentProperties.Company

#Custom Properties

This example below demonstrates how to define the custom document properties for a workbook. Use the DocumentProperties.Custom property to get access to a storage of all user-defined properties specified in a document. To set an individual custom property with the specified name, use the DocumentCustomProperties.Item property.

View Example

' Set the custom document properties.
workbook.DocumentProperties.Custom("Checked by") = "Nancy Davolio"
workbook.DocumentProperties.Custom("Revision") = 3
workbook.DocumentProperties.Custom("Completed") = True
workbook.DocumentProperties.Custom("Published") = Date.Now
' Display the specified custom properties in a worksheet.
Dim customPropertiesNames As IEnumerable(Of String) = workbook.DocumentProperties.Custom.Names
Dim rowIndex As Integer = 2
For Each propertyName As String In customPropertiesNames
    worksheet(rowIndex, 1).Value = propertyName
    worksheet(rowIndex, 2).Value = workbook.DocumentProperties.Custom(propertyName)
    If worksheet(rowIndex, 2).Value.IsDateTime Then
        worksheet(rowIndex, 2).NumberFormat = "[$-409]m/d/yyyy h:mm AM/PM"
    End If
    rowIndex += 1
Next propertyName

Use the DocumentCustomProperties.LinkToContent property to associate the desired custom property with the cell or cell range content, as show on the code snippet below.

View Example

'Define a name to the cell to be linked to the custom property
workbook.DefinedNames.Add("checked_by", "D6")

'Link the custom property to the named cell
workbook.DocumentProperties.Custom.LinkToContent("Checked by", "checked_by")

To remove all the custom document properties from a workbook, use the DocumentCustomProperties.Clear method.

View Example

' Remove all custom document properties.
workbook.DocumentProperties.Custom.Clear()