Class CustomDocumentPropertyCollection

CustomDocumentPropertyCollection class

A collection of custom document properties.

public class CustomDocumentPropertyCollection : DocumentPropertyCollection

Properties

NameDescription
Capacity { get; set; }
Count { get; }
Item { get; }Returns a DocumentProperty object by index.(Inherited from DocumentPropertyCollection.)
Item { get; set; }
virtual Item { get; }Returns a DocumentProperty object by the name of the property.(Inherited from DocumentPropertyCollection.)

Methods

NameDescription
Add(string, bool)Creates a new custom document property of the PropertyType.Boolean data type.
Add(string, DateTime)Creates a new custom document property of the PropertyType.DateTime data type.
Add(string, double)Creates a new custom document property of the PropertyType.Float data type.
Add(string, int)Creates a new custom document property of the PropertyType.Number data type.
Add(string, string)Creates a new custom document property of the PropertyType.String data type.
AddLinkToContent(string, string)Creates a new custom document property which links to content.
BinarySearch(DocumentProperty)
BinarySearch(DocumentProperty, IComparer<DocumentProperty>)
BinarySearch(int, int, DocumentProperty, IComparer<DocumentProperty>)
Clear()
Contains(DocumentProperty)
Contains(string)Returns true if a property with the specified name exists in the collection.(Inherited from DocumentPropertyCollection.)
CopyTo(DocumentProperty[])
CopyTo(DocumentProperty[], int)
CopyTo(int, DocumentProperty[], int, int)
Exists(Predicate<DocumentProperty>)
Find(Predicate<DocumentProperty>)
FindAll(Predicate<DocumentProperty>)
FindIndex(Predicate<DocumentProperty>)
FindIndex(int, Predicate<DocumentProperty>)
FindIndex(int, int, Predicate<DocumentProperty>)
FindLast(Predicate<DocumentProperty>)
FindLastIndex(Predicate<DocumentProperty>)
FindLastIndex(int, Predicate<DocumentProperty>)
FindLastIndex(int, int, Predicate<DocumentProperty>)
GetEnumerator()
IndexOf(DocumentProperty)
IndexOf(string)Gets the index of a property by name.(Inherited from DocumentPropertyCollection.)
IndexOf(DocumentProperty, int)
IndexOf(DocumentProperty, int, int)
LastIndexOf(DocumentProperty)
LastIndexOf(DocumentProperty, int)
LastIndexOf(DocumentProperty, int, int)
Remove(string)Removes a property with the specified name from the collection.(Inherited from DocumentPropertyCollection.)
RemoveAt(int)Removes a property at the specified index. (2 methods)
UpdateLinkedPropertyValue()Updates values of all custom properties that are linked to content(use cell value of linked range to update value of custom property).
UpdateLinkedRange()Updates all ranges that are linked to custom properties(use the value of custom document property to update cell value of linked range).

Remarks

Each DocumentProperty object represents a custom property of a container document.

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.Properties;
    using System;

    public class CustomDocumentPropertyCollectionDemo
    {
        public static void CustomDocumentPropertyCollectionExample()
        {
            // Instantiate a Workbook object
            Workbook workbook = new Workbook();

            // Retrieve a list of all custom document properties of the Excel file
            CustomDocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;

            // Add custom document properties
            customProperties.Add("Author", "John Doe");
            customProperties.Add("Revision", 3);
            customProperties.Add("LastModified", DateTime.Now);
            customProperties.Add("IsFinal", true);
            customProperties.Add("Rating", 4.5);

            // Add a linked custom document property
            customProperties.AddLinkToContent("LinkedProperty", "Sheet1!A1");

            // Update linked property values
            //customProperties.UpdateLinkedPropertyValue();
            customProperties.UpdateLinkedRange();

            // Accessing custom document properties
            DocumentProperty authorProperty = customProperties["Author"];
            DocumentProperty revisionProperty = customProperties["Revision"];
            DocumentProperty lastModifiedProperty = customProperties["LastModified"];
            DocumentProperty isFinalProperty = customProperties["IsFinal"];
            DocumentProperty ratingProperty = customProperties["Rating"];
            DocumentProperty linkedProperty = customProperties["LinkedProperty"];

            // Print custom document properties
            Console.WriteLine($"Author: {authorProperty.Value}");
            Console.WriteLine($"Revision: {revisionProperty.ToInt()}");
            Console.WriteLine($"Last Modified: {lastModifiedProperty.ToDateTime()}");
            Console.WriteLine($"Is Final: {isFinalProperty.ToBool()}");
            Console.WriteLine($"Rating: {ratingProperty.ToDouble()}");
            Console.WriteLine($"Linked Property: {linkedProperty.Value}");

            // Save the workbook
            workbook.Save("CustomDocumentPropertiesExample.xlsx");
            workbook.Save("CustomDocumentPropertiesExample.pdf");
        }
    }
}

See Also