Skip to main content

XlHyperlink.DisplayText Property

Compatibility setting. Gets or sets the text to be displayed for the specified hyperlink.

Namespace: DevExpress.Export.Xl

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

NuGet Package: DevExpress.Printing.Core

Declaration

public string DisplayText { get; set; }

Property Value

Type Description
String

A String value that specifies the display text for a hyperlink.

Remarks

This property has no effect in the spreadsheet application UI, but its value is retained (it can be set and obtained).

To specify the text representing a hyperlink, do the following.

  • Create a cell that should contain a hyperlink text. Normally, it is the top-left cell of the range associated with the hyperlink.
  • Set the cell’s IXlCell.Value property to the string value that specifies the display text for the hyperlink.
  • Format the specified text as a hyperlink by setting the IXlCell.Formatting property to the XlCellFormatting.Hyperlink object.

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