如何在TaskManager中退出EXCEL.EXE? [英] How to quit EXCEL.EXE in the TaskManager ??

查看:85
本文介绍了如何在TaskManager中退出EXCEL.EXE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在程序中打开,编辑和保存Word文档和excel工作簿.
我写了一些类似下面的代码.
程序退出后,
我发现TaskManager中的WORD.EXE已退出,但EXCEL.EXE仍在运行.
为什么oExcel.quit()不起作用?
请给我一些建议,谢谢!!

I try do open, edit, and save a word document and an excel workbook in my program.
I write some code like below.
After the program exit,
I find the WORD.EXE in TaskManager is quit, but the EXCEL.EXE is still running.
Why does the oExcel.quit() not work??
Please give me some advice, thanks!!

                Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
                
                object fileName = @"D:\Combo.docx";
                Document oDoc = oWord.Application.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
...                
                oDoc.Close(ref saveChange, ref oMissing, ref oMissing);
                oDoc = null;
                oWord.Quit(ref saveChange, ref oMissing, ref oMissing);
                oWord = null;
...
                Microsoft.Office.Interop.Excel.Application oExcel = new Microsoft.Office.Interop.Excel.Application();
                String fileName3 = @"D:\Combo.xlsx";
                Workbook excelWorkbook = oExcel.Workbooks.Open(fileName3,
                    0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "",
                    true, false, 0, true, false, false);
...
                excelWorkbook.Close(saveChange, oMissing, oMissing);
                excelWorkbook = null;
                oExcel.Quit();
                oExcel = null;

推荐答案

I''v之前也有相同的问题.

找不到防水解决方案,但确实找到了99%的时间都可以工作的东西.

调用quit方法后,释放对象并运行垃圾收集器
I''v had the same problem before.

Didn''t find a waterproof solution but did find something that works 99% of the time.

After you call the quit methode release the object and run the garbagecollector
oExcel.quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel);
GC.collect();







No guarantees tho


不能保证为什么?您显然已经放弃了与它的连接.
Why does it matter ? You''ve obviously abandoned your connection to it.


因为我不知道如何检查EXCEL是否正在运行.
如果我运行程序10次,则TaskManager中将有10个EXCEL.EXE.
此外,我的程序稍后将在服务器上运行,我不希望它保留EXCEL.exe来容纳系统资源.
Because I don''t know how to check if the EXCEL is running.
If I run my program 10 times, there will be 10 EXCEL.EXE in the TaskManager.
Besides, my program will run on a server later, I don''t want it to keep an EXCEL.exe to hold the system resource.


这篇关于如何在TaskManager中退出EXCEL.EXE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆