CustomDocumentPropertyCollection.Add

Add(string, string)

Creates a new custom document property of the PropertyType.String data type.

public DocumentProperty Add(string name, string value)
ParameterTypeDescription
nameStringThe name of the property.
valueStringThe value of the property.

Return Value

The newly created property object.

Examples

using System;
using Aspose.Cells;

namespace AsposeCellsExamples
{
    public class CustomDocumentPropertyCollectionMethodAddWithStringStringDemo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            workbook.CustomDocumentProperties.Add("startdate", "ToneyTest");
            
            Console.WriteLine("Custom Property Value: " + 
                workbook.CustomDocumentProperties["startdate"].Value);
                
            workbook.Save("output.xlsx", SaveFormat.Xlsx);
        }
    }
}

See Also


Add(string, int)

Creates a new custom document property of the PropertyType.Number data type.

public DocumentProperty Add(string name, int value)
ParameterTypeDescription
nameStringThe name of the property.
valueInt32The value of the property.

Return Value

The newly created property object.

Examples

using System;
using Aspose.Cells;

namespace AsposeCellsExamples
{
    public class CustomDocumentPropertyCollectionMethodAddWithStringInt32Demo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            workbook.Worksheets.Add("Sheet1");
            
            // Add custom document properties
            workbook.CustomDocumentProperties.Add("textProperty", "Sample Text");
            workbook.CustomDocumentProperties.Add("numericProperty", 42);
            
            // Save the workbook
            workbook.Save("output.xlsx");
            
            // Verify the properties
            Workbook loadedWorkbook = new Workbook("output.xlsx");
            Console.WriteLine("Text Property Value: " + loadedWorkbook.CustomDocumentProperties["textProperty"].Value);
            Console.WriteLine("Numeric Property Value: " + loadedWorkbook.CustomDocumentProperties["numericProperty"].Value);
        }
    }
}

See Also


Add(string, DateTime)

Creates a new custom document property of the PropertyType.DateTime data type.

public DocumentProperty Add(string name, DateTime value)
ParameterTypeDescription
nameStringThe name of the property.
valueDateTimeThe value of the property.

Return Value

The newly created property object.

Examples

using System;
using Aspose.Cells;

namespace AsposeCellsExamples
{
    public class CustomDocumentPropertyCollectionMethodAddWithStringDateTimeDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            
            // Add a custom document property with DateTime value
            string propertyName = "CreationDate";
            DateTime propertyValue = new DateTime(2023, 5, 15, 10, 30, 0, DateTimeKind.Local);
            workbook.CustomDocumentProperties.Add(propertyName, propertyValue);

            // Save the workbook
            workbook.Save("output.xlsx", SaveFormat.Xlsx);
            
            // Verify the property was added
            Console.WriteLine("Added property: {0} = {1}", 
                propertyName, 
                workbook.CustomDocumentProperties[propertyName].Value);
        }
    }
}

See Also


Add(string, bool)

Creates a new custom document property of the PropertyType.Boolean data type.

public DocumentProperty Add(string name, bool value)
ParameterTypeDescription
nameStringThe name of the property.
valueBooleanThe value of the property.

Return Value

The newly created property object.

Examples

using System;
using Aspose.Cells;
using Aspose.Cells.Properties;

namespace AsposeCellsExamples
{
    public class CustomDocumentPropertyCollectionMethodAddWithStringBooleanDemo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            CustomDocumentPropertyCollection customProperties = workbook.CustomDocumentProperties;

            // Add boolean custom property
            customProperties.Add("IsApproved", true);

            // Display the added property
            DocumentProperty property = customProperties["IsApproved"];
            Console.WriteLine($"Name: {property.Name}, Value: {property.Value}, Type: {property.Type}");

            // Save the workbook
            workbook.Save("CustomPropertiesExample.xlsx");
        }
    }
}

See Also


Add(string, double)

Creates a new custom document property of the PropertyType.Float data type.

public DocumentProperty Add(string name, double value)
ParameterTypeDescription
nameStringThe name of the property.
valueDoubleThe value of the property.

Return Value

The newly created property object.

Examples

using System;
using Aspose.Cells;
using Aspose.Cells.Properties;

namespace AsposeCellsExamples
{
    public class CustomDocumentPropertyCollectionMethodAddWithStringDoubleDemo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            CustomDocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;

            // Demonstrate Add method with String and Double parameters
            customProperties.Add("Rating", 4.5);
            customProperties.Add("Score", 8.75);

            // Access and display the added properties
            DocumentProperty ratingProperty = customProperties["Rating"];
            DocumentProperty scoreProperty = customProperties["Score"];

            Console.WriteLine($"Rating: {ratingProperty.ToDouble()}");
            Console.WriteLine($"Score: {scoreProperty.ToDouble()}");

            workbook.Save("CustomDocumentPropertiesWithDoubleValues.xlsx");
        }
    }
}

See Also