c#如何关闭Excel进程

如题所述

GC.WaitForPendingFinalizers();}方法2:引用下面命名空间using System.Runtime.InteropServices;using System.Diagnostics;#region 关闭Excel进程[DllImport("User32.dll", CharSet = CharSet.Auto)]//这个函数有两个参数,第一个参数是窗口句柄 由FindWindow获取,第二个参数是存放进程ID的变量。例如://GetWindowThreadProcessId 该函数返回创建指定窗口线程的标识和创建窗口的进程的标识符,后一项是可选的public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);public void KillExcel(Microsoft.Office.Interop.Excel._Application excel){IntPtr t = new IntPtr(excel.Hwnd);//得到这个句柄,得到这款内存入口int m = 0;GetWindowThreadProcessId(t, out m);//得到本进程的唯一IDProcess pro = Process.GetProcessById(m);//获取当前Excel进程
温馨提示:答案为网友推荐,仅供参考
相似回答