Epplus use Excel Styles like Hyperlink

Christian Sauer picture Christian Sauer · Sep 20, 2013 · Viewed 9.4k times · Source

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;

Answer

liang picture liang · Oct 21, 2013

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.