Back to Devexpress

How to: Add a Hyperlink to a Cell

officefileapi-12407-spreadsheet-document-api-examples-cells-how-to-add-a-hyperlink-to-a-cell.md

latest2.7 KB
Original Source

How to: Add a Hyperlink to a Cell

  • Sep 19, 2023
  • 2 minutes to read

This example demonstrates how to create a hyperlink to a web page or range in a workbook. To do this, use the HyperlinkCollection.Add method with the passed cell or cell range into which a hyperlink should be inserted, a target web page or workbook location and other parameters.

Important

The maximum number of hyperlinks in a worksheet is 65,530.

All hyperlinks created in a worksheet are contained in the HyperlinkCollection collection returned by the Worksheet.Hyperlinks property. To adjust an existing hyperlink, use properties of the Hyperlink object that can be accessed by the hyperlink index from the HyperlinkCollection collection. To get all hyperlinks contained in the specified cell range, use the HyperlinkCollection.GetHyperlinks method.

To remove hyperlinks, use the HyperlinkCollection.Remove or HyperlinkCollection.RemoveAt method. The Worksheet.ClearHyperlinks method deletes all hyperlinks from the specified range of cells.

View Example

csharp
// Create a hyperlink to a web page.
Cell cell = worksheet.Cells["A1"];
worksheet.Hyperlinks.Add(cell, "https://www.devexpress.com/", true, "DevExpress");

// Create a hyperlink to a cell range in a workbook.
CellRange range = worksheet.Range["C3:D4"];
Hyperlink cellHyperlink = worksheet.Hyperlinks.Add(range, "Sheet2!B2:E7", false, "Select Range");
cellHyperlink.TooltipText = "Click Me";
vb
' Create a hyperlink to a web page.
Dim cell As Cell = worksheet.Cells("A1")
worksheet.Hyperlinks.Add(cell, "https://www.devexpress.com/", True, "DevExpress")

' Create a hyperlink to a cell range in a workbook.
Dim range As CellRange = worksheet.Range("C3:D4")
Dim cellHyperlink As Hyperlink = worksheet.Hyperlinks.Add(range, "Sheet2!B2:E7", False, "Select Range")
cellHyperlink.TooltipText = "Click Me"