How does XlsIO handle empty string display text in hyperlinks?

23 Jun 20262 minutes to read

As per Microsoft Excel behavior, hyperlinks cannot be assigned with empty display text values. When the display text of a hyperlink is set to an empty string, Excel automatically uses the hyperlink address itself as the display text. Syncfusion XlsIO follows the same behavior.

If a user does not provide a TextToDisplay value explicitly after assigning a hyperlink Address, XlsIO uses the address value as the display text to match Excel behavior. If TextToDisplay is assigned after the Address, that value is used.

//Case 1: Without TextToDisplay - address itself is used as display text
IHyperLink hyperlink1 = sheet.HyperLinks.Add(sheet.Range["A1"]);
hyperlink1.Type = ExcelHyperLinkType.Url;
hyperlink1.Address = "http://www.syncfusion.com"; //Display text will be "http://www.syncfusion.com"

//Case 2: With TextToDisplay - provided text is used as display text
IHyperLink hyperlink2 = sheet.HyperLinks.Add(sheet.Range["A2"]);
hyperlink2.Type = ExcelHyperLinkType.Url;
hyperlink2.Address = "http://www.syncfusion.com";
hyperlink2.TextToDisplay = "syncfusion"; //Display text will be "syncfusion"
//Case 1: Without TextToDisplay - address itself is used as display text
IHyperLink hyperlink1 = sheet.HyperLinks.Add(sheet.Range["A1"]);
hyperlink1.Type = ExcelHyperLinkType.Url;
hyperlink1.Address = "http://www.syncfusion.com"; //Display text will be "http://www.syncfusion.com"

//Case 2: With TextToDisplay - provided text is used as display text
IHyperLink hyperlink2 = sheet.HyperLinks.Add(sheet.Range["A2"]);
hyperlink2.Type = ExcelHyperLinkType.Url;
hyperlink2.Address = "http://www.syncfusion.com";
hyperlink2.TextToDisplay = "syncfusion"; //Display text will be "syncfusion"
'Case 1: Without TextToDisplay - address itself is used as display text
Dim hyperlink1 As IHyperLink = sheet.HyperLinks.Add(sheet.Range("A1"))
hyperlink1.Type = ExcelHyperLinkType.Url
hyperlink1.Address = "http://www.syncfusion.com" 'Display text will be "http://www.syncfusion.com"

'Case 2: With TextToDisplay - provided text is used as display text
Dim hyperlink2 As IHyperLink = sheet.HyperLinks.Add(sheet.Range("A2"))
hyperlink2.Type = ExcelHyperLinkType.Url
hyperlink2.Address = "http://www.syncfusion.com"
hyperlink2.TextToDisplay = "syncfusion" 'Display text will be "syncfusion"