Retrieve Hyperlinks from an Excel Sheet in C#, VB.NET

Spire.XLS supports to insert hyperlinks in Excel, and modify or remove hyperlinks in an existing Excel document. This article presents how to retrieve hyperlink information from an Excel worksheet in C# and VB.NET.

Step 1: Create a Workbook object and load a sample Excel file.

Workbook wb = new Workbook();
wb.LoadFromFile(@"C:\Users\Administrator\Desktop\Hyperlinks.xlsx");

Step 2: Get the first worksheet.

Worksheet sheet = wb.Worksheets[0];

Step 3: Get the hyperlink information from the worksheet.

foreach (var item in sheet.HyperLinks)
{
    string address = item.Address;
    CellRange range = item.Range;       
    Console.WriteLine(string.Format("Cell[{0},{1}] contains URL: {2}", range.Row, range.Column, address));
}

Output:

Retrieve Hyperlinks from an Excel Sheet in C#, VB.NET

Full Code:

[C#]
Workbook wb = new Workbook();
wb.LoadFromFile(@"C:\Users\Administrator\Desktop\Hyperlinks.xlsx");

Worksheet sheet = wb.Worksheets[0];
foreach (var item in sheet.HyperLinks)
{
    string address = item.Address;
    CellRange range = item.Range;
    Console.WriteLine(string.Format("Cell[{0},{1}] contains URL: {2}", range.Row, range.Column, address));
}
[VB.NET]
Dim wb As Workbook =  New Workbook() 
wb.LoadFromFile("C:\Users\Administrator\Desktop\Hyperlinks.xlsx")
 
Dim sheet As Worksheet =  wb.Worksheets(0) 
Dim item As var
For Each item In sheet.HyperLinks
    Dim address As String =  item.Address 
    Dim range As CellRange =  item.Range 
    Console.WriteLine(String.Format("Cell[{0},{1}] contains URL: {2}", range.Row, range.Column, address))
Next