Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I export very large amount of data to excel

I'm currently using EPPlus to export data to excel. It works admirably for small amount of data. But it consume a lots of memory for large amount of data to export.

I've briefly take a look at OOXML and/or the Microsoft Open XML SDK 2.5. I'm not sure I can use it to export data to Excel?

There is also third party provider libraries.

I wonder what solution could do the job properly of exporting very large amount of data in good performance and not taking to much spaces (ideally less than 3x the amount of data to export) ?

Update: some extra requirements... I need to be able to export "color" information (that exclude CSV) and I would like something easy to manage like EPPlus library (exclude the XML format itself). I found another thread and they recommend Aspose or SpreadsheetGear which I'm trying. I put first answer as ok. Thanks to all.

Update 2016-02-16 Just as information... We now use SpreadSheetGear and we love it. We required support once and it was awesome.

Thanks

like image 769
Eric Ouellet Avatar asked Sep 30 '13 18:09

Eric Ouellet


People also ask

How do I export large data in Excel?

On the External Data tab, in the Export group, click Excel. In the Export - Excel Spreadsheet dialog box, review the suggested file name for the Excel workbook (Access uses the name of the source object). If you want, you can modify the file name. In the File Format box, select the file format that you want.

How do I import a large amount of data into Excel?

Go to the Data tab > From Text/CSV > find the file and select Import. In the preview dialog box, select Load To... > PivotTable Report.

How much data can be exported to Excel?

By default, the export limit is set to 50,000 rows, but through the Client performance options page, system administrators can adjust the export limit as high as 1 million rows.


2 Answers

EPPlus to export data to excel. It works admirably for small amount of data. But it consume a lots of memory for large amount of data to export.

A few years ago, I wrote a C# library to export data to Excel using the OpenXML library, and I faced the same situation.

It worked fine until you started to have about 30k+ rows, at which point, the libraries would be trying to cache all of your data... and it'd run out of memory.

However, I fixed the problem by using the OpenXmlWriter class. This writes the data directly into the Excel file (without caching it first) and is much more memory efficient.

And, as you'll see, the library is incredibly easy to use, just call one CreateExcelDocument function, and pass it a DataSet, DataTable or List<>:

// Step 1: Create a DataSet, and put some sample data in it
DataSet ds = CreateSampleData();

// Step 2: Create the Excel .xlsx file
try
{
    string excelFilename = "C:\\Sample.xlsx";
    CreateExcelFile.CreateExcelDocument(ds, excelFilename);
}
catch (Exception ex)
{ 
    MessageBox.Show("Couldn't create Excel file.\r\nException: " + ex.Message);
    return;
}

You can download the full source code for C# and VB.Net from here:

Mike's Export to Excel

Good luck !

like image 174
Mike Gledhill Avatar answered Oct 19 '22 12:10

Mike Gledhill


If your requirements are simple enough, you can just use CSV.

If you need more detail, look into SpreadsheetML. It's an XML schema that you can use to create a text document that Excel can open natively. It supports formulas, multiple worksheets per workbook, formatting, etc.

like image 37
Joel Coehoorn Avatar answered Oct 19 '22 13:10

Joel Coehoorn