简体   繁体   English

如何导出要在Excel工作表中编写的大数据集(大约40k行和26列)

[英]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). 我们有一个非常大的数据集(大约40k行)。 I want to write to excel file. 我想写excel文件。

I have already tried writing to excel file writing data cell by cell and it works. 我已经尝试过写入excel文件逐个单元地写入数据并且它可以工作。

The problem i face is , it takes lot of time to write to excel. 我面临的问题是,写入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. 而不是循环遍历每一行/列,将完整数据集分配给内存中的数组 - 然后将此数组分配给相同维度的Range对象。 In VBA, this would look like: 在VBA中,这看起来像:

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#... 希望你能把它翻译成c#...

If you write directly to excel, the idea from Albert works - but it will still be slow. 如果你直接写到excel,阿尔伯特的想法是有效的 - 但它仍然会很慢。 I would use a library like EPPLUS to write large amounts of data to excel - it is faster and more reliable. 我会使用像EPPLUS这样的库来编写大量数据来实现excel - 它更快,更可靠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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