BorderCollection.Item

BorderCollection indexer

Gets the Border element at the specified index.

public Border this[BorderType borderType] { get; }
ParameterDescription
borderTypeThe border to be retrieved.

Return Value

The element at the specified index.

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using System;

    public class BorderCollectionPropertyItemDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();

            // Create a sample worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Add some data to make the example meaningful
            worksheet.Cells["A1"].Value = "Sample Data";

            try
            {
                // Get the cell and its style
                Cell cell = worksheet.Cells["A1"];
                Style style = cell.GetStyle();

                // Access the BorderCollection from the style
                BorderCollection borders = style.Borders;

                // Display the current value of the Item property (read operation)
                // Note: The Item property is read-only and returns a Border object
                // The Item property requires a BorderType parameter
                Border border = borders[BorderType.LeftBorder];
                Console.WriteLine("Border type: " + border.LineStyle);
                Console.WriteLine("Border color: " + border.Color);

                // Save the result
                workbook.Save("ItemDemo.xlsx");
                Console.WriteLine("Item property has been demonstrated");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
    }
}

See Also