I was trying to create a cell with a hyper-link as per below, but why is this hyper link not displaying under-line in Excel.
public static void AddHyperLinkText(this ExcelRange range, string hyperLink, string displayText)
{
range.Hyperlink = new ExcelHyperLink(hyperLink);
range.Value = displayText;
}
Could you help me?
Best Regards, Sue
You need to assign a Hyperlink style to the cell. You may need to create it in the workbook as EPPlus does not seem to have this built-in. To create the style (requires System.Drawing) :
private static void AddHyperLinkStyle(ExcelWorkbook wb)
{
if (!wb.Styles.NamedStyles.Any(x => x.Name == "Hyperlink"))
{
var s = wb.Styles.CreateNamedStyle("Hyperlink");
s.Style.Font.UnderLine = true;
s.Style.Font.Color.SetColor(Color.Blue);
}
}
Then you can assign it like this:
range.Hyperlink = new ExcelHyperLink(hyperLink, displayText);
range.Style = "Hyperlink";
Note that you can set the text and link in the same line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With