C#excel关闭过程仍然存在

时间:2011-09-14 11:13:06

标签: c# wpf excel process

我打开并关闭mC#的excel书,就像这样

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

但是stil lan EXCEL.EXE进程在任务列表中运行了,为什么? 当我完成时,如何“杀死”关于excel的一切? 用“.Quit()”是不够的,把引用放到null?

或者在C#堆中还有一些尚未存在的魔术引用 解除引用?

/斯蒂芬

1 个答案:

答案 0 :(得分:3)

试试这个..

oXL.quit()

//注意,oXL仍指向excel

System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oXL)
oXL = Nothing