Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Epplus Hyper Link without Under-line

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

like image 702
Sue Su Avatar asked Feb 12 '26 06:02

Sue Su


1 Answers

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.

like image 169
innomatics Avatar answered Feb 18 '26 16:02

innomatics