Search code examples
stylesepplus

Epplus use Excel Styles like Hyperlink


I am trying to style some cells, I'd like to use the standard "Hyperlink" Style, but I am unable to find it.

here is my best guess code, but the Workbook does not contain a style other than "standard"

      var hLinkStyle = (from s in dataSheet.Workbook.Styles.NamedStyles where s.Name == "Hyperlink" select s).FirstOrDefault();
      hyperlinkCell.StyleName = hLinkStyle.Name;

Solution

  • Try to create a named style and set it to the cell as follows:

    // string link = "your link".
    // worksheet is your worksheet reference.
    var namedStyle = worksheet.Workbook.Styles.CreateNamedStyle("HyperLink");
    namedStyle.Style.Font.UnderLine = true;
    namedStyle.Style.Font.Color.SetColor(Color.Blue);
    cell.Hyperlink = new ExcelHyperLink(link);
    cell.StyleName = namedStyle.Name;
    cell.Value = link;
    

    Please refer to EPP example for detail.