The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.

How to: Specify Document Properties

  • 3 min to read
Important

The Workbook class is defined in the DevExpress.Docs.v19.2.dll assembly. Add this assembly to your project to use the workbook functionality. You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use this assembly in production code. Refer to the DevExpress Subscription page for pricing information.

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 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 (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

This example demonstrates how to specify the standard document properties for a workbook using the Workbook.DocumentProperties property.

// 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

// 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.

//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.

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