Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Epplus use Excel Styles like Hyperlink

Tags:

styles

epplus

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;
like image 762
Christian Sauer Avatar asked Sep 20 '13 12:09

Christian Sauer


1 Answers

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.

like image 191
liang Avatar answered Nov 14 '22 09:11

liang