I was under the impression that if you insert rows before you set the values / style etc that it was suppose to improve performance, perhaps I was misinterpreting this.
I altered my code a bit to apply the data validation to all cells at once:
I altered my code a bit to apply the data validation to all cells at once:
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");
var validationRanges = ws.Range("AA1:AA1");
IXLRanges ranges = ws.Ranges("AA1:AA1");
ranges = new XLRanges
// Insert rows first
ws.Row(totalRows).InsertRowsAbove(totalRows);
// Insert some values
for (int i = 1; i <= totalRows; i++)
{
ranges.Add(ws.Cell(i, 1));
Console.Clear();
Console.Write("{0:P1}",((double)i/(double)totalRows));
}
ranges.SetDataValidation().List(listRange);
}
wb.SaveAs(@"C:\Test2.xlsm");
}
timer.Stop();
Console.WriteLine();
Console.WriteLine("Took {0}s", timer.Elapsed.TotalSeconds);
This seemed to speed it up.