Skip to main content

IXlSheet.Hyperlinks Property

Provides access to the collection of hyperlinks contained in a worksheet.

Namespace: DevExpress.Export.Xl

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

Declaration

Property Value

Type Description
IList<XlHyperlink>

A collection of XlHyperlink objects contained in worksheet cells.

Remarks

To create a new hyperlink, initialize an instance of the XlHyperlink class, set its XlHyperlink.Reference and XlHyperlinkBase.TargetUri properties to specify the location of the hyperlink in a worksheet and its destination, respectively, and then append the created hyperlink to the Hyperlinks collection by using its Add method. For details, refer to the How to: Add a Hyperlink to a Cell example.

To remove hyperlinks, use the Remove, RemoveAt or Clear method of the Hyperlinks collection.

Example

Note

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

// 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);
        }
    }
}
See Also