c# - export to excel throwing System.outofmemoryexception when more than 70k rows (Closed XML) -
i using closedxml export datatable excel in asp.net. works fine if export less 50k rows throwing exception when export more rows. has 31 columns. spliting datatable 10000 rows adding datatable seperate sheet. appreciate if 1 me. below code.
xlworkbook wb = new xlworkbook(); foreach (datatable dtdiv in splitdt) //to remove special characters avoid format exception(the datatable has xml content) { foreach (datarow row in dtdiv.rows) { (int = 0; < 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++; } filestream fs = new filestream(server.mappath("test.xlsx"), filemode.create); wb.saveas(fs); fs.close();
i have tried using following
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();
Comments
Post a Comment