优化语法

时间:2017-02-13 19:45:03

标签: c# c#-4.0 vsto epplus epplus-4

此语法有效 - 但完成大约需要3分钟, WAY 为高。有没有办法重写这种语法进行优化?我知道使用此语法的语法的第一个问题是使用Microsoft Excel Interop但是我无法为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);
    }

修改

除非我错过了显而易见的事情,否则我看起来不像是有探查器。 DEBUG MENU

0 个答案:

没有答案