I am trying to generate excel sheet for a large data about a million records. But when using the below code I am getting nothing. The code hangs up after line : wb.SaveAs(MyMemoryStream);
. I am using closed XML for the purpose. Can you please guide what can be done to save large data as excel.
My Code:
private void DownloadExcel()
{
String Attachment = "attachment; filename=TestFile.xlsx";
Response.ClearContent();
DataTable dt = ds.Tables[0];
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(dt, "Data");
wb.Style.Font.FontName = "Courier New";
// wb.Cell("A1:A+" + colCount + "").Style.Font.Bold = true;
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", Attachment);
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.SuppressContent = true; // Gets or sets a value indicating whether to send HTTP content to the client.
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
}
I am ok with any other library as well to save the data as XML.