Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClosedXML. Adding DataTable to existing Excel worksheet

Tags:

c#

excel

openxml

How using ClosedXML library in fastest way (from performance point of view) add values from DataTable to already existing Excel worksheet?

NOTE: There is way to create new worksheet with DataTable parameter, but the main issue is in adding values to existing worksheet.

like image 522
Anatolii Gabuza Avatar asked Jan 19 '23 14:01

Anatolii Gabuza


1 Answers

If you're dealing with millions of cells and you want to insert the data as fast as possible while consuming the minimum amount of memory then SAX is the way to go.

If you want ClosedXML to do the work for you then use:

cell.Value = dataTable;
or
cell.SetValue(dataTable);
or
cell.InsertData(dataTable);
or
cell.InsertTable(dataTable);

See the "Inserting Data/Tables" section of the Documentation

like image 148
Manuel Avatar answered Feb 14 '23 10:02

Manuel