Reputation: 647
I am open and close an excel book fro mC# like this
Microsoft.Office.Interop.Excel.Application oXL = null;
Microsoft.Office.Interop.Excel.Workbook excelWorkbook = null;
try
{
excelWorkbook = oXL.Workbooks.Open(MyFile,
0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);
.....
....
....
excelWorkbook.Save();
excelWorkbook.Close(Microsoft.Office.Interop.Excel.XlSaveAction.xlSaveChanges, Type.Missing, Type.Missing);
oXL.Quit();
excelWorkbook = null;
oXL = null;
}
catch { }
But there is stil lan EXCEL.EXE process left running in the task list, why ? how do I "kill" everything about excel when I am done ? Is it not enough with ".Quit()" and put the reference to null ?
or is there some magic reference left in the C# heap somewhere that have not been dereferenced ?
/Stefan
Upvotes: 2
Views: 2740
Reputation: 948
Try this..
oXL.quit()
// Note, oXL still points to excel
System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oXL)
oXL = Nothing
Upvotes: 3