Back to Devexpress

HyperlinkCollection.Add(CellRange, String, Boolean, String) Method

officefileapi-devexpress-dot-spreadsheet-dot-hyperlinkcollection-dot-add-x28-devexpress-dot-spreadsheet-dot-cellrange-system-dot-string-system-dot-boolean-system-dot-string-x29.md

latest10.3 KB
Original Source

HyperlinkCollection.Add(CellRange, String, Boolean, String) Method

Adds a hyperlink into the specified cell or cell range and returns the newly created object.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
Hyperlink Add(
    CellRange range,
    string uri,
    bool isExternal,
    string displayText
)
vb
Function Add(
    range As CellRange,
    uri As String,
    isExternal As Boolean,
    displayText As String
) As Hyperlink

Parameters

NameTypeDescription
rangeCellRange

A CellRange object that specifies a cell or cell range where a hyperlink is inserted. This value is assigned to the Hyperlink.Range property.

| | 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.

| | displayText | String |

A String value that specifies text to be displayed for a hyperlink. This value is assigned to the Hyperlink.DisplayText property and specifies the top left cell value of the range into which a hyperlink is added.

|

Returns

TypeDescription
Hyperlink

A Hyperlink object that specifies the created hyperlink.

|

Remarks

The Add method appends a Hyperlink object to the end of the collection.

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.

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"

The following code snippets (auto-collected from DevExpress Examples) contain references to the Add(CellRange, String, Boolean, String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/CellActions.cs#L278

csharp
Cell cell = worksheet.Cells["A1"];
worksheet.Hyperlinks.Add(cell, "http://www.devexpress.com/", true, "DevExpress");

wpf-spreadsheetcontrol-api-part-1/CS/SpreadsheetControl_WPF_API/SpreadsheetActions/CellActions.cs#L231

csharp
Cell cell = worksheet.Cells["A1"];
worksheet.Hyperlinks.Add(cell, "http://www.devexpress.com/", true, "DevExpress");

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/CellActions.cs#L125

csharp
Cell cell = worksheet.Cells["A1"];
worksheet.Hyperlinks.Add(cell, "http://www.devexpress.com/", true, "DevExpress");

asp-net-mvc-spreadsheet-modify-document/CS/DXWebApplication1/Controllers/HomeController.cs#L44

csharp
cell1.Fill.BackgroundColor = Color.WhiteSmoke;
worksheet.Hyperlinks.Add(cell1, "https://documentation.devexpress.com/OfficeFileAPI/14912/Spreadsheet-Document-API", true, "Spreadsheet Document API");
break;

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/CellActions.vb#L114

vb
Dim cell As Cell = worksheet.Cells("A1")
worksheet.Hyperlinks.Add(cell, "http://www.devexpress.com/", True, "DevExpress")
' Create a hyperlink to a cell range in a workbook.

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/CellActions.vb#L254

vb
Dim cell As Cell = worksheet.Cells("A1")
worksheet.Hyperlinks.Add(cell, "http://www.devexpress.com/", True, "DevExpress")

wpf-spreadsheetcontrol-api-part-1/VB/SpreadsheetControl_WPF_API/SpreadsheetActions/CellActions.vb#L210

vb
Dim cell As Cell = worksheet.Cells("A1")
worksheet.Hyperlinks.Add(cell, "http://www.devexpress.com/", True, "DevExpress")

asp-net-mvc-spreadsheet-modify-document/VB/DXWebApplication1/Controllers/HomeController.vb#L35

vb
cell1.Fill.BackgroundColor = Color.WhiteSmoke
    worksheet.Hyperlinks.Add(cell1, "https://documentation.devexpress.com/OfficeFileAPI/14912/Spreadsheet-Document-API", True, "Spreadsheet Document API")
Case "drawBorders"

See Also

HyperlinkCollection Interface

HyperlinkCollection Members

DevExpress.Spreadsheet Namespace