下面的代码工作,但excel.exe进程仍然运行,即使我退出Excel.我正在使用Office 2013并引用Office.Interop.Excel的正确导入 我错过了什么 Sub demo() Dim xls As New Excel.Application Dim book As Excel.Workbook Dim o
我错过了什么
Sub demo() Dim xls As New Excel.Application Dim book As Excel.Workbook Dim oSheet As Excel.Worksheet xls.Workbooks.Open("Test.xlsx") book = xls.ActiveWorkbook oSheet = book.ActiveSheet oSheet.Cells(1, 2).Value = "testing" book.Save() book.Close() xls.Workbooks.Close() xls.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(book) System.Runtime.InteropServices.Marshal.ReleaseComObject(xls) oSheet = Nothing book = Nothing xls = Nothing GC.Collect() End Sub如果你仍然遇到问题,你试图杀死这个过程吗?
Process[] procs = Process.GetProcessesByName("name"); foreach (Process proc in procs) proc.Kill();
不知道它是否会按照你想要的方式工作,但这是一个想法.