[]
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. GcExcel 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 properties:
Type: Indicates the type of document property value
LinkToContent: Indicates whether the property is connected to the content
LinkSource: Indicates the linked content source
Name: Indicates the name of the property
Value: Indicates the value of the property
The BuiltInDocumentPropertyCollection of IWorkbook interface is a collection of built-in properties. The built-in properties can be set by using BuiltInDocumentProperties property 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.
IWorkbook workbook = new Workbook();
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Range["A1"].Value = "hello";
// Add a defined name.
workbook.Names.Add("Headings", "=Sheet1!$A$1");
//Set values for built-in document properties
workbook.BuiltInDocumentProperties.Author = "John";
workbook.BuiltInDocumentProperties.Company = "GrapeCity";
// Add a custom document property.
IDocumentProperty property = workbook.CustomDocumentProperties.AddLinkToContent("Detail", "Headings");
var value = property.Value; // The value is "Hello".
var type = property.Type; // The Type is String.
workbook.Save("DocumentProperties.xlsx");
workbook.Save("DocumentProperties.pdf");
Limitations
The following document properties are not supported in GcExcel.
Number of Characters
Number of Bytes
Number of Lines
Number of Paragraphs
Number of Slides
Number of Notes
Number of Hidden Slides
Number of Multimedia Clips
Number of Characters (with spaces)