Skip to content

Commit 468c12f

Browse files
Bold Create AgentMohan2401
andcommitted
Use XlsIO Worksheet.SetValue and migrant range for large reads
Co-authored-by: MOHAN CHANDRAN <93247949+Mohan2401@users.noreply.github.com>
1 parent 277cb1b commit 468c12f

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

‎XlsIO.PerformanceBenchmark/Program.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
new GemBoxEngine(),
4141
};
4242

43+
string? engineFilter = Environment.GetEnvironmentVariable("BENCH_ENGINE");
44+
if (!string.IsNullOrWhiteSpace(engineFilter))
45+
{
46+
engines = engines.Where(engine => engine.Name.Contains(engineFilter, StringComparison.OrdinalIgnoreCase)).ToArray();
47+
}
48+
4349
string[] scenarios = string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("BENCH_ONLY"))
4450
? [
4551
"Open and Save",

‎XlsIO.PerformanceBenchmark/SyncfusionEngine.cs‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Data;
2+
using System.Globalization;
23
using Syncfusion.XlsIO;
34

45
sealed class SyncfusionEngine : IExcelEngine
@@ -25,8 +26,7 @@ public void Run(string scenario, string sourcePath, DataTable table, string outp
2526
case "Create and Save":
2627
{
2728
IWorkbook workbook = application.Workbooks.Create(1);
28-
IWorksheet sheet = workbook.Worksheets[0];
29-
WriteGrid(sheet, table);
29+
WriteGrid(workbook.Worksheets[0], table);
3030
using FileStream output = File.Create(outputStem + ".xlsx");
3131
workbook.SaveAs(output);
3232
workbook.Close();
@@ -79,23 +79,20 @@ public void Run(string scenario, string sourcePath, DataTable table, string outp
7979
}
8080
}
8181

82+
// https://help.syncfusion.com/document-processing/excel/excel-library/net/improving-performance#write
8283
static void WriteGrid(IWorksheet sheet, DataTable table)
8384
{
84-
var values = new object[table.Rows.Count + 1, table.Columns.Count];
8585
for (int c = 0; c < table.Columns.Count; c++)
8686
{
87-
values[0, c] = table.Columns[c].ColumnName;
87+
sheet.SetValue(1, c + 1, table.Columns[c].ColumnName);
8888
}
8989

9090
for (int r = 0; r < table.Rows.Count; r++)
9191
{
9292
for (int c = 0; c < table.Columns.Count; c++)
9393
{
94-
values[r + 1, c] = table.Rows[r][c];
94+
sheet.SetValue(r + 2, c + 1, Convert.ToString(table.Rows[r][c], CultureInfo.InvariantCulture) ?? string.Empty);
9595
}
9696
}
97-
98-
sheet.ImportArray(values, 1, 1);
9997
}
10098
}
101-

0 commit comments

Comments
 (0)