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”
code:
<code> var hLinkStyle = (from s in dataSheet.Workbook.Styles.NamedStyles where s.Name == "Hyperlink" select s).FirstOrDefault();
hyperlinkCell.StyleName = hLinkStyle.Name;
you can add a hyperlink to your worksheet by pressing
In closed XML, the “Hyperlink” style you are trying to access is not a built-in named style like “Standard.” Instead, it’s added as a separate object to a specific cell. To create a hyperlink and style it, you need to use the “Hyperlink” object provided by the library.
Here’s how you can add a hyperlink to a cell and style it:
using (var workbook = new XLWorkbook())
{
var worksheet = workbook.Worksheets.Add(“Sheet1”);// Create a hyperlink in cell A1 with the link and display text
var hyperlinkCell = worksheet.Cell(“A1”);
hyperlinkCell.Value = “Click here!”;
hyperlinkCell.Hyperlink = new XLHyperlink(“https://www.example.com”);// Style the hyperlink cell with your desired formatting
var hLinkStyle = workbook.Style;
hLinkStyle.Font.FontColor = XLColor.Blue; // Change font color to blue
hLinkStyle.Font.Underline = XLFontUnderlineValues.Single; // Add underlinehyperlinkCell.Style = hLinkStyle;
workbook.SaveAs(“Hyperlink.xlsx”);
}
In the above code, we create a hyperlink using the XLHyperlink
object, and then we apply the desired style (blue font color and underline) to the cell using the hLinkStyle
we defined.
Note: The “Hyperlink” style you were trying to access might not be available in the library by default. You can create a custom style and apply it to the cell as shown in the example above.