简体   繁体   English

使用C#.Net在Excel中进行超链接

[英]Hyperlink in Excel using C#.Net

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. 我正在使用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;
}

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");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM