locked
SystemOutOfMemory when I save XLWorkbook RRS feed

  • Question

  • User1300559023 posted

    Hi everyone,

    I generate a .xlsx file with XLWorkbook Librarie, but when I want to save it in my desktop I get "SystemOutOfMemory Exception" this is my piece of code:

    MemoryStream memoryStream = new MemoryStream();
    
    workbook.SaveAs(memoryStream);
    
    memoryStream.WriteTo(httpResponse.OutputStream);
    
    memoryStream.Close();

    and I tried with :

    MemoryStream memoryStream = new MemoryStream();
    
    workbook.SaveAs(@"C:\myFile.xlsx");
    
    memoryStream.WriteTo(httpResponse.OutputStream);
    
    memoryStream.Close();

    Any help please?

    Monday, November 19, 2018 10:05 PM

All replies

  • User1520731567 posted

    HI KatiDev,

    Unfortunately, I can't reproduce your problem.

    But you could refer to this article.

    Here are some common reasons:

    1.String Concatenation

    2.Fragmentation in the Managed Heap

    3.Fragmentation in the Virtual Address (VA) Space

    4.Returning Large Sets of Data

    5.Running in a Production Environment with Tracing Enabled

    6.Leaking Native Resources

    Hope my answer could be helpful to you.

    Best Regards.

    Yuki Tao

    Tuesday, November 20, 2018 8:48 AM
  • User1300559023 posted

    HI KatiDev,

    Unfortunately, I can't reproduce your problem.

    But you could refer to this article.

    Here are some common reasons:

    1.String Concatenation

    2.Fragmentation in the Managed Heap

    3.Fragmentation in the Virtual Address (VA) Space

    4.Returning Large Sets of Data

    5.Running in a Production Environment with Tracing Enabled

    6.Leaking Native Resources

    Hope my answer could be helpful to you.

    Best Regards.

    Yuki Tao

    Thank you Yuki, I tried the same functions with a small file and it works.

    There is another function or technique to use ?

    Thanks in advance,

    Thursday, November 22, 2018 10:37 AM
  • User1520731567 posted

    HI KatiDev,

    I can't see any problems from this part of code.

    There are many reasons for this problem.

    Maybe your program is entering an infinite loop, maybe your file is too big...

    Could you post more code(contains libraries),so that i can reproduce your issue.

    Best Regards.

    Yuki Tao

    Tuesday, November 27, 2018 9:46 AM
  • User1300559023 posted

    Hi, 

    I'm using ClosedXml library, and when I debug it still bloqued at workbook.SaveAs(mystream) or generetad an "Out of Memory Exception".

    When I used a path : workbook.saveAs(myPath), the file is created with 0 ko, and still bloqued with no response.

    Thank you  

    Wednesday, November 28, 2018 6:00 AM
  • User-1038772411 posted

    I do not get this issue when i use this code. may be there is an issue regarding memory space in C: drive. so please change location to save this file which i mentioned in my below code.
    and if you face any issue when use those code than use httpResponse instead of response.



    XLWorkbook workbook = new XLWorkbook(); 
    var ws = workbook.Worksheets.Add("Demo Sheet");
    ws.Cell(1, 2).Value = "Hello World"; 
    string datetime = Convert.ToString(DateTime.Today.ToString("dd-MM-yyyy")).Trim();
    string filepath = "E:";
    string filename = @"\xyz" + "_" + datetime + ".xlsx";
    string combinepath = filepath + filename;
    
    Response.Clear();
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AddHeader("content-disposition", "attachment;filename="+ combinepath);
    
    using (MemoryStream memoryStream = new MemoryStream())
    {
    workbook.SaveAs(combinepath);
    memoryStream.WriteTo(Response.OutputStream);
    memoryStream.Close();
    }

    Friday, November 30, 2018 7:56 AM
  • User1300559023 posted

    Hi Addweb,

    It works for me too for small data, when I have +3000 rows I get this problem

    Monday, December 3, 2018 7:36 AM