Class ExternalLinkCollection

ExternalLinkCollection class

Represents external links collection in a workbook.

public class ExternalLinkCollection : IEnumerable

Properties

NameDescription
Count { get; }Gets the number of elements actually contained in the collection.
Item { get; }Gets the ExternalLink element at the specified index.

Methods

NameDescription
Add(string, string[])Adds an external link.
Add(DirectoryType, string, string[])Add an external link .
Clear()Removes all external links.
Clear(bool)Removes all external links.
GetEnumerator()Get an enumerator that iterates through this collection.
RemoveAt(int)Removes the specified external link from the workbook.
RemoveAt(int, bool)Removes the specified external link from the workbook.

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using System;

    public class ExternalLinkCollectionDemo
    {
        public static void ExternalLinkCollectionExample()
        {
            // Open a file with external links
            Workbook workbook = new Workbook("ExternalLinkCollectionExample_original.xlsx");

            // Get the external links collection
            ExternalLinkCollection externalLinks = workbook.Worksheets.ExternalLinks;

            // Display the count of external links
            Console.WriteLine("Number of external links: " + externalLinks.Count);

            // Iterate through the external links and display their data sources
            for (int i = 0; i < externalLinks.Count; i++)
            {
                ExternalLink link = externalLinks[i];
                Console.WriteLine("External Link " + i + " Data Source: " + link.DataSource);
            }

            // Add a new external link
            int newLinkIndex = externalLinks.Add("newLink.xls", new[] { "Sheet1" });
            Console.WriteLine("Added new external link at index: " + newLinkIndex);

            // Change the data source of the first external link
            if (externalLinks.Count > 0)
            {
                externalLinks[0].DataSource = "d:\\link.xlsx";
                Console.WriteLine("Updated data source of the first external link.");
            }

            // Save the workbook
            workbook.Save("ExternalLinkCollectionExample.xlsx");

            // Clear all external links
            externalLinks.Clear();
            Console.WriteLine("Cleared all external links.");

            // Save the workbook after clearing external links
            workbook.Save("ExternalLinkCollectionExample2.xlsx");
        }
    }
}

See Also