如何结束EXCEL.EXE进程? [英] How to end excel.exe process?
问题描述
我尝试得到vb.net 3.5 Excel中的Excel文件的表名但它打开,但EXCEL.EXE仍然在这个过程中。如何阻止不从任务管理器杀EXCEL.EXE进程?
i m trying to get excel sheet-name of a excel file from vb.net 3.5 however it opens but excel.exe still remains in the process. How do i stop the process without killing the excel.exe from task manager?
我意识到新excel.application启动新的进程。
i realise new excel.application starts new process.
我试图使用退出,关闭和处置.......................没有什么工作
i tried to use quit, close and dispose.......................nothing worked
下面是我的code
Dim sheetName As New Excel.XlSheetType
Dim newExcell As New Excel.Application
Dim newWorkBook As Excel.Workbook = app.Workbooks.Open(MyFileName)
Dim worksheetName As String
Dim ws As Excel.Worksheet = CType(WB.Worksheets.Item(1), Excel.Worksheet)
worksheetName = ws.Name
我不能使用kill因为有其他运行Excel应用程序,让我怎么关闭这个特殊的EXCEL.EXE的处理器。请帮忙
I cannot use kill because there are other excel application running, so how do i close this particular excel.exe from processor. Please help
推荐答案
此知识库文章介绍问题
不过,这不是一个容易解决的,因为你必须确保你调用Marshal.ReleaseComObject的每个Excel对象实例化 - 而且很容易错过一个
However, it's not an easy one to solve, as you must ensure you call Marshal.ReleaseComObject on every Excel object you instantiate - and it's very easy to miss one.
例如,下面的code的隐含的引用一个工作簿对象:
For example, the following code implicitly references a Workbooks object:
Dim newWorkBook As Excel.Workbook = app.Workbooks.Open(MyFileName)
要释放工作簿对象,你需要引用它的明确的,让你有一个参考,可以在其中调用Marshal.ReleaseComObject的:
To release the Workbooks object you need to reference it explicitly, so that you have a reference on which you can call Marshal.ReleaseComObject:
Dim objWorkbooks As Excel.Workbooks = app.Workbooks
Dim newWorkbook As Excel.Workbook = objWorkbooks.Open(MyFileName)
...
Marshal.ReleaseComObject(objWorkbooks)
Marshal.ReleaseComObject(newWorkbook)
...
您还应该使用try /最后,以确保即使抛出异常ReleaseComObject的调用。
You also should use Try/Finally to ensure ReleaseComObject is called even if an exception is thrown.
这篇关于如何结束EXCEL.EXE进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!