HyperlinkBase.SetUri(String, Boolean) Method
Sets the hyperlink destination.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v24.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
uri | String | A String value that specifies a web page, existing file, e-mail address or cell range in the current workbook to which a hyperlink refers. This value is assigned to the HyperlinkBase.Uri property. |
isExternal | Boolean | A Boolean value that specifies whether a hyperlink refers to an external resource (true) or to a cell range within the current workbook (false). This value is assigned to the HyperlinkBase.IsExternal property. |
Remarks
When an end-user clicks a cell range or picture, the associated hyperlink navigates to its destination. Pass a hyperlink destination to the HyperlinkCollection.Add method as a parameter when adding a hyperlink to a cell range. The Hyperlink.SetUri method allows you to change the target location of an existing hyperlink. To create a hyperlink for a picture, call the Shape.InsertHyperlink method and also pass the hyperlink destination as a parameter. To change the location to where the hyperlink associated with the shape refers, use the SetUri method of the ShapeHyperlink object.
The following table lists possible locations to which hyperlinks can refer. A hyperlink can be external or internal depending on its target location.
Hyperlink Destination | Description | Hyperlink Type | Example |
---|---|---|---|
Web Page | A hyperlink opens the specified web page in the default browser. | External | “https://www.devexpress.com/“ |
Existing File or Directory | A hyperlink opens a file or directory. Uri is a path to a file and file name, or a path to a directory. A path can be absolute or relative to the directory where the current workbook is located. | External | “C:\Temp\MyDocument.xlsx” “..\..\..\MyBook.xlsx” “D:\“ |
E-Mail Address | A hyperlink opens the default mail client for the specified e-mail address. Uri is an e-mail address preceded by the “mailto:” prefix. | External | “mailto:support@devexpress.com” |
Cell Range | A hyperlink refers to a cell or cell range within the current workbook. Uri is a cell reference or defined name preceded by the worksheet name. | Internal | “Sheet2!A1:C3” “Sheet2!range_name” |
Example
This example demonstrates how to create a hyperlink to a web page or cell range in a workbook. To do this, use the HyperlinkCollection.Add method with the cell or cell range into which a hyperlink should be inserted, the target web page, or the workbook location passed along with 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, which 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, HyperlinkCollection.RemoveAt or HyperlinkCollection.Clear method. The Worksheet.ClearHyperlinks method deletes all hyperlinks from the specified range of cells.
// 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";