C# 将数据写入excel时,我得到错误System.OutOfMemoryException
调试时,我收到错误“-`((Microsoft.Office.Interop.Excel.Range)(xlsheet.Cells)).Value2'引发了类型为“System.OutOfMemoryException”的异常。我在下面指定了调试时出错的位置。我正在读取行和列,并在excel中的特定位置尝试插入数据C# 将数据写入excel时,我得到错误System.OutOfMemoryException,c#,asp.net,excel,C#,Asp.net,Excel,调试时,我收到错误“-`((Microsoft.Office.Interop.Excel.Range)(xlsheet.Cells)).Value2'引发了类型为“System.OutOfMemoryException”的异常。我在下面指定了调试时出错的位置。我正在读取行和列,并在excel中的特定位置尝试插入数据 public static void Update_Daily_Resolution(string Daily_Resolution_Path, List<Summary>
public static void Update_Daily_Resolution(string Daily_Resolution_Path, List<Summary> Flux, List<Summary> Active,List<Summary> OnHold)
{
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(Daily_Resolution_Path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item("April 15 - 21");
range = xlWorkSheet.UsedRange;
for (int i = 1; i <= range.Rows.Count; i++) //updation of VMS
{
for (int j = 1; j <= 17; j++)
{
string str1 = (string)(range.Cells[i, j] as Excel.Range).Text;
if (str1 == "VMS" && str1 != "RES")
{
int rCnt = i + 1;
for (int cCnt = 1; cCnt <= 17; cCnt++)//looping through each column
{
string str2 = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Text;
if (str2 == "20-Apr")//searching for the right column to update the data
{
int iCount = rCnt + 1;//fetching the row value
int jCount = cCnt;//fetching the column value
**xlWorkSheet.Cells[iCount, jCount] = Flux[0].VMS; //Here i am getting this error while debugging**
xlWorkSheet.Cells[iCount + 2, jCount] = Convert.ToString(Convert.ToInt32(OnHold[0].VMS)-Convert.ToInt32(xlWorkSheet.Cells[iCount+4,jCount-1].Text)); //Tickets moved to hold
xlWorkSheet.Cells[iCount+3, jCount] = Active[0].VMS; // Ending Backlog
xlWorkSheet.Cells[iCount + 4, jCount] = OnHold[0].VMS; //Ending Hold
}
}
}
}
}
xlWorkBook.Save();
//MyBook.SaveCopyAs(Incident_Path);
//xlWorkSheet.Close("Ageing");
xlApp.Quit();
//Call the garbage collector to collect and wait for finalizers to finish.
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.ReleaseComObject(xlWorkSheet);
Marshal.ReleaseComObject(xlWorkBook);
Marshal.ReleaseComObject(xlWorkBook);
Marshal.ReleaseComObject(xlApp);
Process[] excelProcs = Process.GetProcessesByName("EXCEL"); //use to the Kill method of the .Net Process object.
foreach (Process proc in excelProcs)
{
proc.Kill();
}
}
public static void Update\u Daily\u Resolution(字符串Daily\u Resolution\u路径、列表流量、列表活动、列表保持)
{
xlApp=new Excel.Application();
xlWorkBook=xlApp.Workbooks.Open(每日解析路径,0,true,5,“,”,true,Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,“\t”,false,false,0,true,1,0);
xlWorkSheet=(Excel.Worksheet)xlWorkBook.Worksheets.get_项(“4月15-21日”);
range=xlWorkSheet.UsedRange;
对于(int i=1;i)您尝试读取或写入多少条记录?大约100条记录。打开任务管理器。打开多少Excel实例?您尝试读取或写入多少条记录?大约100条记录。打开任务管理器。打开多少Excel实例?