Error System.OutOutMemory when exporting excel c #

1

I need to export a report to excel in C #, but when I use this code, the 'System.OutOfMemory' exception is returned in line: wb.Worksheets.Add(dt, "Relatorio"); per account of the size of excel (580mil lines).

using (XLWorkbook wb = new XLWorkbook())
{
    string db = Request.QueryString["DB"].ToString().Replace("-", "_");
    string de = Request.QueryString["DB"].ToString().Replace("-", "_");


    wb.Worksheets.Add(dt, "Relatorio");
    wb.Worksheet(1).Range("A1:O1").Style.Fill.BackgroundColor = XLColor.Gainsboro;
    wb.Worksheet(1).Range("A1:O1").Style.Font.FontColor = XLColor.DimGray;

    Response.Clear();
    Response.Buffer = true;
    Response.Charset = "";
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AddHeader("content-disposition", "attachment;filename=InventoryReport___" + db + "___" +
                       de + "___" + DateTime.Now.Day + "_" + DateTime.Now.Month + "_" +
                       DateTime.Now.Year + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" +
                       DateTime.Now.Second + ".xlsx");

    using (MemoryStream MyMemoryStream = new MemoryStream())
    {

        wb.SaveAs(MyMemoryStream);
        MyMemoryStream.WriteTo(Response.OutputStream);
        Response.Flush();
        Response.End();
    }
}
    
asked by anonymous 18.04.2018 / 03:58

0 answers