0

这种语法有效 - 但大约需要 3 分钟才能完成,这太高了。有没有办法重写这个语法进行优化?我知道这种语法的第一个问题是使用 Microsoft Excel 互操作,但是我无法编写语法EPPlus来实现这一点。

可以重新编写以优化代码并加快流程吗?

public static Excel.Application xlApp;
public static Excel.Workbook xlWorkBook;
public static Excel.Worksheet xlWorkSheet;
public static string sheetprefix;

private void btnOneClickClickClick_Click(object sender, EventArgs e)
{
    SecondSetOfHyperLinks();
    FirstSetOfHyperLinks();     
}
public static void SecondSetOfHyperLinks()
{
    sheetprefix = "FS";
    long lr, i;
    string cellVal;
    WS = xlApp.ActiveWorkbook.ActiveSheet;
    lr = WS.Cells[WS.Rows.Count, 2].End(Excel.XlDirection.xlUp).Row;
    for (i = 2; i <= lr; i++)
    {
        Object Anchor = WS.Cells[i, 7];
        Object TextToDisplay = Convert.ToString(WS.Cells[i, 9]);
        cellVal = WS.Cells[i, 1].Value;
        cellVal = cellVal.Substring(0, Math.Min(28, cellVal.Length));
        rangeToHoldHyperlink = WS.Range["G" + i];
        xlApp.ActiveSheet.Hyperlinks.Add(Anchor, "", "'" + "FS " + cellVal + "'!A1", "", TextToDisplay);
    }
}
public static void FirstSetOfHyperLinks()
{
    sheetprefix = "SE";
    long lr, i;
    string cellVal;
    WS = xlApp.ActiveWorkbook.ActiveSheet;
    lr = WS.Cells[WS.Rows.Count, 2].End(Excel.XlDirection.xlUp).Row;
    for (i = 2; i <= lr; i++)
    {
        Object Anchor = WS.Cells[i, 7];
        Object TextToDisplay = Convert.ToString(WS.Cells[i, 9]);
        cellVal = WS.Cells[i, 1].Value;
        cellVal = cellVal.Substring(0, Math.Min(28, cellVal.Length));
        rangeToHoldHyperlink = WS.Range["G" + i];
        xlApp.ActiveSheet.Hyperlinks.Add(Anchor, "", "'" + "SE " + cellVal + "'!A1", "", TextToDisplay);
    }

编辑

除非我遗漏了明显的东西,否则看起来我没有分析器。 调试菜单

4

0 回答 0