我像这样用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#堆中还有一些未引用的魔术引用
取消引用?
/斯蒂芬
最佳答案
尝试这个..
oXL.quit()
//注意,oXL仍指向excel
System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oXL)
oXL = Nothing