Skip to main content
A newer version of this page is available. .

XlHyperlink Class

Represents a hyperlink in a worksheet.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v18.1.Core.dll

Declaration

Remarks

An XlHyperlink object specifies a link associated with a cell or cell range that navigates to a certain location on the Internet, to a file, to a place in a workbook, or sends an email. Hyperlinks contained in a worksheet are stored in the IXlSheet.Hyperlinks collection.

The Hyperlink object’s members allow you to change different hyperlink parameters. For example, you can specify the hyperlink destination (XlHyperlinkBase.TargetUri), the cell range where the hyperlink should be inserted (XlHyperlink.Reference), and the tooltip text (XlHyperlinkBase.Tooltip).

For an example on how to use the Excel Export API to create hyperlinks, refer to the How to: Add a Hyperlink to a Cell topic.

Example

Note

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

// 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 = "#Sheet1!C5";
            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 = "http://www.devexpress.com";
            sheet.Hyperlinks.Add(hyperlink);
        }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the XlHyperlink class.

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.

Inheritance

See Also