简体   繁体   中英

How to export Large dataset (around 40k rows and 26columns), to be written in excel sheet

We have a very large dataset (around 40k rows). I want to write to excel file.

I have already tried writing to excel file writing data cell by cell and it works.

The problem i face is , it takes lot of time to write to excel.

Is there any efficient way to do the same.

Instead of looping through every row/column, assign the full dataset to an array in memory - and then assign this array to a Range object of the same dimension. In VBA, this would look like:

Dim arr as Variant
arr = ... ' Your code to fill the array here
Set Workbook("YourWorkbook").Worksheets("Worksheetname"). _ 
    Range(1,1).Resize(40000, 20).Value = arr

Hope you can translate this to c#...

If you write directly to excel, the idea from Albert works - but it will still be slow. I would use a library like EPPLUS to write large amounts of data to excel - it is faster and more reliable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM