Karthik K

Karthik K

  • 1.2k
  • 429
  • 45.2k

Getting Exception when excel export More than 5 Lakhs Record ?

Aug 19 2020 2:43 AM
Hi All,
 
I am facing issue when I try to export more than 5 Lakh Records in Asp.Net Excel Export. I am getting
 
Exception of type 'System.OutOfMemoryException' was thrown.
 
The above exception. If anyone knows for the solution, Suggest me with Sample Code.
 
Code which i used :
  1. //Create a dummy GridView  
  2. GridView GridView1 = new GridView();  
  3. GridView1.ShowFooter = true;  
  4. GridView1.AllowPaging = false;  
  5. GridView1.DataSource = Dt2;  
  6. GridView1.DataBind();  
  7. Response.Clear();  
  8. Response.Buffer = true;  
  9. Response.AddHeader("content-disposition",  
  10. "attachment;filename=MemberHistory.xls");  
  11. Response.Charset = "";  
  12. Response.ContentType = "application/vnd.ms-excel";  
  13. StringWriter sw = new StringWriter();  
  14. HtmlTextWriter hw = new HtmlTextWriter(sw);  
  15. for (int i = 0; i < GridView1.Rows.Count; i++)  
  16. {  
  17. //Apply text style to each Row  
  18. GridView1.Rows[i].Attributes.Add("class""textmode");  
  19. }  
  20. GridView1.RenderControl(hw);  
  21. //style to format numbers to string  
  22. string style = @"<style> TD { mso-number-format:\@; } </style>";  
  23. Response.Write(style);  
  24. Response.Output.Write(sw.ToString());  
  25. Response.Flush();  
  26. Response.End();  
Thanks in advance
 
Karthik K

Answers (2)