Skip to main content

How to: Specify Document Properties

  • 3 minutes to read

Important

The Workbook class is defined in the DevExpress.Docs.v24.2.dll assembly. Add this assembly to your project to use the Workbook API. You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this assembly in production code.

The document properties are metadata associated and stored with a workbook. To specify the standard document properties (such as Title, Author, Subject, Description etc.), use the Workbook.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 (Author, Created), last modified and saved (LastModifiedBy, Modified), or printed (Printed).

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

Built-In Properties

This example demonstrates how to specify the standard document properties for a workbook using the Workbook.DocumentProperties 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

View Example

// Set the custom document properties.
workbook.DocumentProperties.Custom["Revision"] = 3;
workbook.DocumentProperties.Custom["Completed"] = true;
workbook.DocumentProperties.Custom["Published"] = DateTime.Now;
// Display the specified custom properties in a worksheet.
IEnumerable<string> customPropertiesNames = workbook.DocumentProperties.Custom.Names;
int rowIndex = 2;
foreach (string propertyName in customPropertiesNames)
{
    worksheet[rowIndex, 1].Value = propertyName;
    worksheet[rowIndex, 2].Value = workbook.DocumentProperties.Custom[propertyName];
    if (worksheet[rowIndex, 2].Value.IsDateTime)
        worksheet[rowIndex, 2].NumberFormat = "[$-409]m/d/yyyy h:mm AM/PM";
    rowIndex++;
}

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

View Example

//Define a name to the cell to be linked to the custom property
workbook.DefinedNames.Add("checked_by", "E6");

//Connect the custom property with 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();
See Also