Not enough storage is available to complete this operation in ExcelSheet

1

I'm working on Excelsheet of .xls extensions with 4 Sheets in it. I'm writing xml content to all these sheets.After writing to each sheet I'm Saving and Collecting the Garbage using this method

 private static void SaveAndCollecttheGarbage(Microsoft.Office.Interop.Excel.Application excelApp, string path, Microsoft.Office.Interop.Excel.Sheets sheet)
 {
    try
    {
        excelApp.Columns.AutoFit();
        mWorkBook.SaveAs(path, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,
        Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
        Missing.Value, Missing.Value, Missing.Value,
        Missing.Value, Missing.Value);
        mWorkBook.Close(true, Missing.Value, Missing.Value);
        sheet = null;
        mWorkBook = null;
        excelApplication.Quit();
        GC.WaitForPendingFinalizers();
        GC.Collect();
        GC.WaitForPendingFinalizers();
        GC.Collect();
    }
    catch (Exception)
    {
    }
}

This is working fine for all my first 3 sheets but when coming to the my 4th sheet it is throwing an error when the cell value is --------Original------and the data goes on.....

Not enough storage is available to complete this operation. (Exception from HRESULT: 0x8007000E (E_OUTOFMEMORY))

My 4th sheet has more data (1100+ rows) than the other sheets. This is how I'm writing data to my 4th sheet

mWorkBook = excelApplication.Workbooks.Open(excelPath, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); 
                        mSheets = mWorkBook.Worksheets;
                        mWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)mSheets.Add();
                        mWorkSheet.Name = "Case History";
                        int l = 1, m = 1, n = 0;
                        mWorkSheet.Cells[1, 1] = "Id";
                        mWorkSheet.Cells[1, 2] = "Subject";
                        mWorkSheet.Cells[1, 3] = "CustomerHistory";
                        foreach (CaseHistory customerHistory in allCustomerHistory)
                        {
                            n = 0;
                            mWorkSheet.Cells[l + m, ++n] = customerHistory.id;
                            mWorkSheet.Cells[l + m, ++n] = customerHistory.caseSubject;
                            mWorkSheet.Cells[l + m, ++n] = customerHistory.caseBody;
                            m++;
                        }

I cannot find what I'm doing wrong. Isn't it possible to write huge data to excelsheet. If can do help me how to do it

c#
excel
asked on Stack Overflow Jun 3, 2015 by Ajay A • edited Jun 4, 2015 by Ajay A

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0