This syntax works - but it takes roughly 3 minutes to complete, which is WAY to high. Is there a way to re-write this syntax for optimization? I know that the first problem with the syntax with this syntax is using Microsoft Excel Interop however I could not write syntax for EPPlus
to achieve such.
Can this be re-written to optimize the code and speed up the process?
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);
}
Edit
Unless I am missing the obvious, it does not look like I have the profiler.