Back to Devexpress

XlHyperlinkBase Class

corelibraries-devexpress-dot-export-dot-xl-c758ba59.md

latest5.8 KB
Original Source

XlHyperlinkBase Class

Serves as the base for the XlHyperlink and XlPictureHyperlink classes that define hyperlinks for cells and pictures.

Namespace : DevExpress.Export.Xl

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

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public abstract class XlHyperlinkBase
vb
Public MustInherit Class XlHyperlinkBase

Remarks

The XlHyperlinkBase class provides a set of members to specify basic hyperlink parameters, such as a hyperlink destination (XlHyperlinkBase.TargetUri) and tooltip text (XlHyperlinkBase.Tooltip).

The example below demonstrates how to create a hyperlink to cells located in the same or external workbooks, and a web page. For details, refer to the How to: Add a Hyperlink to a Cell topic.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples

csharp
// Create a worksheet.
using (IXlSheet sheet = document.CreateSheet()) {
    using(IXlColumn column = sheet.CreateColumn()) {
        column.WidthInPixels = 300;
    }

    // Create a hyperlink to a cell in the current workbook.
    using (IXlRow row = sheet.CreateRow()) {
        using(IXlCell cell = row.CreateCell()) {
            cell.Value = "Local link";
            cell.Formatting = XlCellFormatting.Hyperlink;
            XlHyperlink hyperlink = new XlHyperlink();
            hyperlink.Reference = new XlCellRange(new XlCellPosition(cell.ColumnIndex, cell.RowIndex));
            hyperlink.TargetUri = $"#'{targetSheet}'!{targetPosition.ToString()}";
            sheet.Hyperlinks.Add(hyperlink);
        }
    }

    // Create a hyperlink to a cell located in the external workbook.
    using (IXlRow row = sheet.CreateRow()) {
        using(IXlCell cell = row.CreateCell()) {
            cell.Value = "External file link";
            cell.Formatting = XlCellFormatting.Hyperlink;
            XlHyperlink hyperlink = new XlHyperlink();
            hyperlink.Reference = new XlCellRange(new XlCellPosition(cell.ColumnIndex, cell.RowIndex));
            hyperlink.TargetUri = "linked.xlsx#Sheet1!C5";
            sheet.Hyperlinks.Add(hyperlink);
        }
    }

    // Create a hyperlink to a web page.
    using (IXlRow row = sheet.CreateRow()) {
        using(IXlCell cell = row.CreateCell()) {
            cell.Value = "External URI";
            cell.Formatting = XlCellFormatting.Hyperlink;
            XlHyperlink hyperlink = new XlHyperlink();
            hyperlink.Reference = new XlCellRange(new XlCellPosition(cell.ColumnIndex, cell.RowIndex));
            hyperlink.TargetUri = "https://www.devexpress.com/";
            sheet.Hyperlinks.Add(hyperlink);
        }
    }
}
vb
' Create a worksheet.
Using sheet As IXlSheet = document.CreateSheet()
    Using column As IXlColumn = sheet.CreateColumn()
        column.WidthInPixels = 300
    End Using

    ' Create a hyperlink to a cell in the current workbook.
    Using row As IXlRow = sheet.CreateRow()
        Using cell As IXlCell = row.CreateCell()
            cell.Value = "Local link"
            cell.Formatting = XlCellFormatting.Hyperlink
            Dim hyperlink As New XlHyperlink()
            hyperlink.Reference = New XlCellRange(New XlCellPosition(cell.ColumnIndex, cell.RowIndex))
            hyperlink.TargetUri = $"#'{targetSheet}'!{targetPosition.ToString()}"
            sheet.Hyperlinks.Add(hyperlink)
        End Using
    End Using

    ' Create a hyperlink to a cell located in the external workbook.
    Using row As IXlRow = sheet.CreateRow()
        Using cell As IXlCell = row.CreateCell()
            cell.Value = "External file link"
            cell.Formatting = XlCellFormatting.Hyperlink
            Dim hyperlink As New XlHyperlink()
            hyperlink.Reference = New XlCellRange(New XlCellPosition(cell.ColumnIndex, cell.RowIndex))
            hyperlink.TargetUri = "linked.xlsx#Sheet1!C5"
            sheet.Hyperlinks.Add(hyperlink)
        End Using
    End Using

    ' Create a hyperlink to a web page.
    Using row As IXlRow = sheet.CreateRow()
        Using cell As IXlCell = row.CreateCell()
            cell.Value = "External URI"
            cell.Formatting = XlCellFormatting.Hyperlink
            Dim hyperlink As New XlHyperlink()
            hyperlink.Reference = New XlCellRange(New XlCellPosition(cell.ColumnIndex, cell.RowIndex))
            hyperlink.TargetUri = "https://www.devexpress.com/"
            sheet.Hyperlinks.Add(hyperlink)
        End Using
    End Using
End Using

.

Inheritance

Object XlHyperlinkBase XlHyperlink

XlPictureHyperlink

See Also

XlHyperlinkBase Members

Use the Excel Export API to Add a Hyperlink to a Cell

DevExpress.Export.Xl Namespace