Hi,
I posted a discussion earlier about Cell Merge Performance. Well the same project I am working on also requires many data validations placed on an excel spreadsheet (can be anywhere from 1000 - 5000 cells with data validations that all point to the same range as a list). I noticed that it takes longer and longer to create the same data validation. Below is some code that is similar to what's being accomplished:
Thank so much!
I posted a discussion earlier about Cell Merge Performance. Well the same project I am working on also requires many data validations placed on an excel spreadsheet (can be anywhere from 1000 - 5000 cells with data validations that all point to the same range as a list). I noticed that it takes longer and longer to create the same data validation. Below is some code that is similar to what's being accomplished:
var timer = System.Diagnostics.Stopwatch.StartNew();
using (XLWorkbook wb = new XLWorkbook(XLEventTracking.Disabled))
{
using (var ws = wb.AddWorksheet("MergeCellsWorksheet"))
{
int totalRows = 5000;
// Create some ranges
ws.Cell("AO1").Value = "A";
ws.Cell("AP1").Value = "B";
ws.Cell("AQ1").Value = "C";
ws.Cell("AR1").Value = "D";
ws.Cell("AS1").Value = "E";
ws.Cell("AT1").Value = "1";
ws.Cell("AU1").Value = "2";
var listRange = ws.Range("AO1:AU1");
// Insert rows first
ws.Row(totalRows).InsertRowsAbove(totalRows);
// Insert some values
for (int i = 1; i <= totalRows; i++)
{
ws.Cell(i, 1).DataValidation.List(listRange);
Console.Clear();
}
}
wb.SaveAs(@"C:\Test2.xlsm");
}
timer.Stop();
Console.WriteLine();
Console.WriteLine("Took {0}s", timer.Elapsed.TotalSeconds);
Is there a way to optimize this?Thank so much!