I am using closedxml to export datatable to excel in asp.net. it works fine if i export less than 50k rows but throwing exception when i export more rows. It has 31 columns. I am Spliting the datatable to 10000 rows then adding the datatable to a seperate sheet. Would appreciate if some one help me. Below is the code.
XLWorkbook wb = new XLWorkbook();
foreach (DataTable dtdiv in splitdt)
{
foreach (DataRow row in dtdiv.Rows)//to remove any special characters to avoid format exception(the datatable has xml content)
{
for (int i = 0; i < dtdiv.Columns.Count; i++)
{
if (dtdiv.Columns[i].DataType == typeof(string))
{
if (row[i] != System.DBNull.Value)
{
row[i] = ReplaceHexadecimalSymbols((string)row[i]);
}
}
}
}
string newString = "report_" + k;
wb.AddWorksheet(dtdiv, newString);
k++;
}
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=" + (String)Session["MatrixOutputFileName"]);
using (MemoryStream memoryStream = new MemoryStream())
{
wb.SaveAs(memoryStream);
memoryStream.WriteTo(Response.OutputStream);
memoryStream.Close();
}
Response.End();