c# 杀掉excel进程

1122hailey 1122hailey 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在Winform中,运用using Excel = Microsoft.Office.Interop.Excel;引用EXCEL,完了发现进程中多了好多excel的进程,找了一些资料,说把跟EXCEL有关的全部做以下处理,就把以下代码写到了winform 的formClosing事件里,可是还是出现EXCEL的进程 ,在以下代码做了断电,好像不执行,不知道哪里的问题,请大家帮忙~

System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ep);
System.Runtime.InteropServices.Marshal.ReleaseComObject(range);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ew);
System.Runtime.InteropServices.Marshal.ReleaseComObject(mySheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheets);
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);

excel = null;
ep = null;
range = null;
ew = null;
mySheet = null;
worksheets = null;
workbooks = null;
workbook = null;
sheet = null;
GC.Collect();
...全文
评论 7
收藏 已收藏
分享
返回顶部
1122hailey
C# 111,128 成员 642,536 内容