没有足够的存储空间可用于在ExcelSheet中完成此操作

时间:2015-06-03 06:22:22

标签: c# excel

我正在处理包含4张表格的.xls扩展程序的Excel表格。我正在为所有这些工作表写xml内容。写完每张工作表后我正在使用这种方法保存和收集垃圾

 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)
    {
    }
}

这对我所有的前3张都很好但是当我来到我的第4张时,当单元格值 --------原始------时,它会抛出错误数据继续.....

没有足够的存储空间来完成此操作。 (HRESULT异常:0x8007000E(E_OUTOFMEMORY))

我的第四张纸比其他纸张有更多数据(1100 + )。这就是我将数据写入第四张的方式

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++;
                        }

我找不到我做错了什么。是不是可以将大量数据写入excelsheet。如果可以帮我怎么做

0 个答案:

没有答案