vb.net – 关闭Excel.exe进程
发布时间:2020-12-17 07:11:33 所属栏目:百科 来源:网络整理
导读:下面的代码工作,但excel.exe进程仍然运行,即使我退出Excel.我正在使用Office 2013并引用Office.Interop.Excel的正确导入 我错过了什么 Sub demo() Dim xls As New Excel.Application Dim book As Excel.Workbook Dim oSheet As Excel.Worksheet xls.Workbook
下面的代码工作,但excel.exe进程仍然运行,即使我退出Excel.我正在使用Office 2013并引用Office.Interop.Excel的正确导入
我错过了什么 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(); 不知道它是否会按照你想要的方式工作,但这是一个想法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |