[英]Hyperlink in Excel using C#.Net
我正在使用ClosedXML從C#代碼生成Excel。我需要在具有多個行的特定列上的超鏈接,並且每個鏈接都是唯一的。
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;
}
但是此循環需要太多時間。 有沒有其他選擇可以跳過此循環。
嘗試以下優化代碼,看看它是否足夠快:
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");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.