L
lasmit42
Guys
I am writing a program which reads the first cell of many Excel
spreadsheets and then takes some actions. The problem that I am
experiencing is that each Excel instance I create persists in memory,
meaning that after a while the machine freezes. Any help would be
greatfuly recieved.
Regards
Lewis
code:
Excel.Application ExcelObj = new Excel.Application();
Excel.Workbook theWorkbook =
ExcelObj.Workbooks.Open(this.sFileName,0,true,5,"","",true,
Excel.XlPlatform.xlWindows,"\t", false, false,0, false, false, false);
Excel.Range range = ExcelObj.get_Range("A1", "A1");
string firstCell = (string)range.Cells.Value2;
ExcelObj.Visible = true; // I see Excel close
ExcelObj.DisplayAlerts = false;
theWorkbook.Close(false, sFileName, true);
ExcelObj.Workbooks.Close();
ExcelObj.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelObj);
System.Runtime.InteropServices.Marshal.ReleaseComObject(theWorkbook);
GC.Collect();
GC.WaitForPendingFinalizers();
theWorkbook = null;
ExcelObj = null;
I am writing a program which reads the first cell of many Excel
spreadsheets and then takes some actions. The problem that I am
experiencing is that each Excel instance I create persists in memory,
meaning that after a while the machine freezes. Any help would be
greatfuly recieved.
Regards
Lewis
code:
Excel.Application ExcelObj = new Excel.Application();
Excel.Workbook theWorkbook =
ExcelObj.Workbooks.Open(this.sFileName,0,true,5,"","",true,
Excel.XlPlatform.xlWindows,"\t", false, false,0, false, false, false);
Excel.Range range = ExcelObj.get_Range("A1", "A1");
string firstCell = (string)range.Cells.Value2;
ExcelObj.Visible = true; // I see Excel close
ExcelObj.DisplayAlerts = false;
theWorkbook.Close(false, sFileName, true);
ExcelObj.Workbooks.Close();
ExcelObj.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelObj);
System.Runtime.InteropServices.Marshal.ReleaseComObject(theWorkbook);
GC.Collect();
GC.WaitForPendingFinalizers();
theWorkbook = null;
ExcelObj = null;