How to Create Hyperlink

Excel hyperlinks provide clickable references to locations within the workbook, different files, web pages, or email addresses. They enhance navigation, allowing quick access to related information and external resources. Hyperlinks create interactive and user-friendly spreadsheets, facilitating easy access to additional data or external content.

IronXL enables the creation of hyperlinks for URLs, opening external files from both local and FTP (File Transfer Protocol) file systems, email addresses, cell addresses, and defined name cells without the use of Interop in .NET C#.

Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green arrow pointer


The Hyperlink property exists in the Cell class. The worksheet["A1"] code returns a Range object, you can use the First method to access the first cell in the range.

Alternatively, you can directly access the cell using the GetCellAt method, allowing you to access the Hyperlink property directly.

Let's explore an example of creating link hyperlinks. Both HTTP and HTTPS protocols are supported.

Before proceeding
Using the GetCellAt method to select an unmodified cell will throw System.NullReferenceException: 'Object reference not set to an instance of an object.'

:path=/static-assets/excel/content-code-examples/how-to/hyperlinks-set-link-hyperlink.cs
using IronXL;

WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Modify the cell's property
workSheet["A1"].Value = "Link to ironpdf.com";

// Set hyperlink at A1 to https://ironpdf.com/
workSheet.GetCellAt(0, 0).Hyperlink = "https://ironpdf.com/";

workBook.SaveAs("setLinkHyperlink.xlsx");
Imports IronXL

Private workBook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
Private workSheet As WorkSheet = workBook.DefaultWorkSheet

' Modify the cell's property
Private workSheet("A1").Value = "Link to ironpdf.com"

' Set hyperlink at A1 to https://ironpdf.com/
workSheet.GetCellAt(0, 0).Hyperlink = "https://ironpdf.com/"

workBook.SaveAs("setLinkHyperlink.xlsx")
$vbLabelText   $csharpLabel

Demonstration

Link Hyperlink

To create a hyperlink to a cell within the same worksheet, simply use the cell's address, such as Z20. However, to create a hyperlink across worksheets, you can use the address convention "worksheetName!address". For example, "Sheet2!A1".

Define name cells can have either workbook(global) or worksheet scope. If you want to create a hyperlink to a defined name within the same worksheet or a defined name with workbook scope, you can specify the name directly. To create a hyperlink for a defined name with worksheet scope on a different worksheet, specify the worksheet name as mentioned above. For example, "Sheet2!Iron".

:path=/static-assets/excel/content-code-examples/how-to/hyperlinks-set-hyperlink-across-worksheet.cs
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);
WorkSheet workSheet1 = workBook.CreateWorkSheet("Sheet1");
WorkSheet workSheet2 = workBook.CreateWorkSheet("Sheet2");

// Create workbook(global) define name
workSheet1["D5"].SaveAsNamedRange("Iron", true);

// Create worksheet define name
workSheet2["D10"].SaveAsNamedRange("Hello", false);

// --== Within the same worksheet ==--
// Set hyperlink to cell Z20
workSheet1["A1"].Value = "Z20";
workSheet1["A1"].First().Hyperlink = "Z20";

// Set hyperlink to define name "Iron"
workSheet1["A2"].Value = "Iron";
workSheet1["A2"].First().Hyperlink = "Iron";

// --== Across worksheet ==--
// Set hyperlink to cell A1 of Sheet2
workSheet1["A3"].Value = "A1 of Sheet2";
workSheet1["A3"].First().Hyperlink = "Sheet2!A1";

// Set hyperlink to define name "Hello" of Sheet2
workSheet1["A4"].Value = "Define name Hello of Sheet2";
workSheet1["A4"].First().Hyperlink = "Sheet2!Hello";

workBook.SaveAs("setHyperlinkAcrossWorksheet.xlsx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Demonstration

Hyperlink Across Worksheet

In addition to the hyperlink types mentioned earlier, IronXL also supports the creation of FTP, file, and email hyperlinks.

  • FTP: Starting with ftp://
  • File: Specify an absolute path starting with file:///
  • Email: Starting with mailto:

Please note
Both FTP and File hyperlinks require the use of absolute paths.

:path=/static-assets/excel/content-code-examples/how-to/hyperlinks-set-other-hyperlink.cs
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Set hyperlink to open file sample.xlsx
workSheet["A1"].Value = "Open sample.xslx";
workSheet["A1"].First().Hyperlink = "ftp://C:/Users/sample.xlsx";

// Set hyperlink to open file sample.xlsx
workSheet["A2"].Value = "Open sample.xslx";
workSheet["A2"].First().Hyperlink = "file:///C:/Users/sample.xlsx";

// Set hyperlink to email example@gmail.com
workSheet["A3"].Value = "example@gmail.com";
workSheet["A3"].First().Hyperlink = "mailto:example@gmail.com";

workBook.SaveAs("setOtherHyperlink.xlsx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Demonstration

Other Types of Hyperlinks

To remove a hyperlink, simply invoke the RemoveHyperlink method. This method can be accessed from the cell object.

:path=/static-assets/excel/content-code-examples/how-to/hyperlinks-remove-hyperlink.cs
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Load("setLinkHyperlink.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Remove hyperlink
workSheet["A1"].First().RemoveHyperlink();

workBook.SaveAs("removeHyperlink.xlsx");
Imports IronXL
Imports System.Linq

Private workBook As WorkBook = WorkBook.Load("setLinkHyperlink.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet

' Remove hyperlink
workSheet("A1").First().RemoveHyperlink()

workBook.SaveAs("removeHyperlink.xlsx")
$vbLabelText   $csharpLabel

Frequently Asked Questions

What is the purpose of hyperlinks in Excel?

Hyperlinks in Excel provide clickable references to locations within the workbook, different files, web pages, or email addresses, enhancing navigation and allowing quick access to related or external information.

How can you create hyperlinks in Excel files using a .NET library?

IronXL allows the creation of hyperlinks for URLs, opening external files from local and FTP file systems, email addresses, cell addresses, and defined name cells without using Interop in .NET C#.

How do you create a hyperlink to a website URL using a .NET library?

To create a hyperlink to a website URL in IronXL, you can set the Hyperlink property of a cell to a Uri object containing the URL, and then save the Excel file.

Can you create hyperlinks across different worksheets in the same workbook?

Yes, you can create hyperlinks across different worksheets by using the address format 'worksheetName!address'.

What types of hyperlinks can be created using a .NET library?

IronXL supports creating hyperlinks for HTTP and HTTPS URLs, FTP links, file paths, and email addresses.

How do you remove a hyperlink from a cell using a .NET library?

To remove a hyperlink from a cell in IronXL, you can use the RemoveHyperlink method on the cell object.

What is the difference between using a cell address and a defined name cell for hyperlinks?

Using a cell address specifies the exact location within a worksheet, while a defined name cell can reference a specific range, making it easier to manage and update links.

Do FTP and file hyperlinks require specific formats when using a .NET library?

Yes, FTP hyperlinks start with 'ftp://', and file hyperlinks require an absolute path starting with 'file:///'.

Is it possible to set an email hyperlink using a .NET library?

Yes, to set an email hyperlink in IronXL, use a Uri object with the 'mailto:' scheme.

What is the advantage of using a .NET library for hyperlinks over Interop?

Using IronXL for hyperlinks in Excel files eliminates the need for Excel Interop, allowing for easier and more efficient code execution within .NET applications.

Chaknith related to Remove Hyperlinks
Software Engineer
Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.