Epplus use Excel Styles like Hyperlink

匿名 (未验证) 提交于 2019-12-03 03:05:02

问题:

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; 

回答1:

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. It worked for me. Hope it helps.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!