Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am having a MVC application. I have to export data to excel from the application. The number of records may go upto lakhs. When we click the button, we get three options....
1. Open --> When i click open it is taking a long time to open the excel with the data.

Can anyone help on how this can be achieved in a quick manner?

What I have tried:

I am loading the data from Database in to a DataSet. Then i loop through the dataset and add it to a worksheet in the excel object.
Posted
Comments
Richard MacCutchan 5-Oct-17 7:27am    
With that amount of data it will always take a long time.
Prakash Sekhar 5-Oct-17 7:33am    
I know but just want to optimize it as much. Any other ways to approach this?
Dave Kreskowiak 5-Oct-17 8:54am    
If you're using Excel Interop:

1) You cannot use in a web application. It may work fine on your DEV machine, but deploy it to a production web server and your code is going to fail at some point.

2) Interop is SLOW. There is no getting around this other than NOT using Interop. Use a library dedicated to this task, like the OpenXML SDK, or the ClosedXML SDK.
Richard Deeming 5-Oct-17 12:16pm    
We can't tell you how to optimize code that we can't see. You either need to show us the relevant parts of your code, or explain how you're exporting the data to Excel.

In general, don't use Interop, and don't just send back HTML with a Content-Type header. Use a server-safe library to generate a real Excel file - for example:

* EPPlus[^];
* ClosedXML[^];
* The OpenXML SDK[^];

But, as Dave said, if it's a large file, there's nothing you can do to speed up the download - unless you can convince your users to upgrade their internet connection speed!
Prakash Sekhar 6-Oct-17 9:33am    
I cannot show the code. I am using CLosed XML only. 10,000 records is taking 3 mins. but it has to be done in 20-25 secs max. Is there any option for this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900