如何使用VB.NET终止Excel进程Excel.exe?
- 内容介绍
- 相关推荐
本文共计242个文字,预计阅读时间需要1分钟。
下面是简化后的内容:
代码工作,但Excel.exe进程仍在运行。我退出Excel。我正在使用Office 2013,并尝试使用Office.Interop.Excel的正确导入。我错误地使用了Sub demo() Dim xls As New Excel.Application Dim book As Excel.Workbook Dim o
下面的代码工作,但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();
不知道它是否会按照你想要的方式工作,但这是一个想法.
本文共计242个文字,预计阅读时间需要1分钟。
下面是简化后的内容:
代码工作,但Excel.exe进程仍在运行。我退出Excel。我正在使用Office 2013,并尝试使用Office.Interop.Excel的正确导入。我错误地使用了Sub demo() Dim xls As New Excel.Application Dim book As Excel.Workbook Dim o
下面的代码工作,但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();
不知道它是否会按照你想要的方式工作,但这是一个想法.

