ExternalConnectionCollection.Item

ExternalConnectionCollection indexer (1 of 2)

Gets the ExternalConnection element at the specified index.

public ExternalConnection this[int index] { get; set; }
ParameterDescription
indexThe zero based index of the element.

Return Value

The element at the specified index.

See Also


ExternalConnectionCollection indexer (2 of 2)

Gets the ExternalConnection element with the specified name.

public ExternalConnection this[string connectionName] { get; }
ParameterDescription
connectionNamethe name of data connection

Return Value

The element with the specified name.

Examples

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

    public class ExternalConnectionCollectionPropertyItemDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            
            try
            {
                // Access the external connections collection
                ExternalConnectionCollection connections = workbook.DataConnections;
                
                // Add a sample connection (if needed for demonstration)
                // This assumes the collection allows adding connections
                // connections.Add(new ExternalConnection());
                
                // Demonstrate accessing an item by name (read operation)
                // Note: In a real scenario, you would need actual connection names
                if (connections.Count > 0)
                {
                    // Get first connection name (if available)
                    string connectionName = connections[0].Name;
                    
                    // Access the Item property
                    ExternalConnection connection = connections[connectionName];
                    
                    // Display connection information
                    Console.WriteLine($"Connection Name: {connection.Name}");
                    Console.WriteLine($"Connection Type: {connection.Type}");
                }
                else
                {
                    Console.WriteLine("No external connections available to demonstrate Item property");
                }
                
                // Save the workbook
                workbook.Save("ExternalConnectionDemo.xlsx");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
    }
}

See Also