I am using ClosedXML to generate excel from c# code.I need hyperlink on one particular column with multiple rows and every link is unique.
for (int i = 2; i <= result.Count + 1; i++)
{
ws.Cell(i, 44).Value = "Download";
url = folderPath + "type=testPhoto&userName=" + Convert.ToString(result[i - 2].testCode);
ws.Cell(i, 44).Hyperlink = new XLHyperlink(url, "Download");
ws.Cell(i, 44).Style.Font.FontColor = XLColor.AirForceBlue;
ws.Cell(i, 44).Style.Font.Underline = XLFontUnderlineValues.Single;
}
But this loop is taking too much time. Is there is any alternative to skip this loop.
Try this optimized code and see if it is fast enough for you:
ws.Column(44).Style.Font.SetFontColor(XLColor.AirForceBlue)
.Font.SetUnderline(XLFontUnderlineValues.Single;
url = folderPath + "type=testPhoto&userName=";
for (int i = 2; i <= result.Count + 1; i++)
{
ws.Cell(i, 44).SetValue("Download").Hyperlink =
new XLHyperlink(url + Convert.ToString(result[i - 2].testCode), "Download");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.