Skip to main content

XlHyperlinkBase.TargetUri Property

Gets or sets the hyperlink destination.

Namespace: DevExpress.Export.Xl

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

NuGet Package: DevExpress.Printing.Core

Declaration

public string TargetUri { get; set; }

Property Value

Type Description
String

A String value that specifies the destination to which a hyperlink refers.

Remarks

When an end-user clicks a cell range or picture, the associated hyperlink navigates to the location returned by the TargetUri property.

You can set the TargetUri property to one of the following values depending on the location to which your hyperlink should refer.

Hyperlink Destination

TargetUri Value

Example

Place in the current workbook

A cell reference or defined name preceded by the worksheet name.

“#Sheet1!B4”

Place in an external workbook

A cell reference or defined name preceded by the path to a file, the workbook and worksheet names.

If a path to the destination workbook is not specified, the path relative to the location of the current workbook will be used.

“D:\Shared\Expenses.xlsx#Sheet1!C5”

“Document.xls#Sheet1!B4”

Web page

A web address.

“https://www.devexpress.com/“

E-mail address

An e-mail address preceded by the “mailto:” prefix.

mailto:support@devexpress.com

Existing File or Directory

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.

“D:\Pictures\Image1.png”

“..\..\..\MyBook.xlsx”

For details, on how to create a hyperlink, refer to the How to: Add a Hyperlink to a Cell example.

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);
        }
    }
}

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

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.

See Also