asp.net - How to export large data to Excel -


In my asp.net application, I have the Criteria page when the user clicks the report button, first of all to a new page The datagrid is tied to the results, then this page is exported to Excel to save the content type method.

This usually works, but when large amount of data comes, the system.outofmemoryexception is thrown away.

Does anyone know a way to fix this problem, or what other useful techniques have to do?

This is probably happening because your application is trying to create a complete Excel spreadsheet in memory and then After completing it, it is distributed to the user. For large datasets, you can easily access all the available memory, which is also applying to dramatically slow down for most users.

Instead, you can try to stream data to the consumer. Despite this how big your dataset will be, it will use the same memory you can get the bytes of Excel spreadsheets, or just convert your data to CSV, and then you can set the HTTP Response Type and let it stream the user. can do.

Here's an example:

  byte [] report doc = GetExportExcel (); Context.Response.ContentType = "application / vnd.ms-excel"; // Set the content nature headers to force the download reference force. response. Adhider ("content-displacement", "attachment; filename =" + "export xl"); // file content byte array reference type. response. BinaryWrite (reportDoc); Detailed tutorial on  


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -