posted @ 2009-04-04 19:22 lab 阅读(389) 评论(0) 编辑

关闭特定excel进程的方法

 

        public void ExplortExcel(string fileName) {
            MyWorkBook.SaveCopyAs(fileName);
        
        }
        public void deleteTempExcel() {
            MyExcel.Quit();
            Kill(MyExcel);

         }

        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
        public static void Kill(Application excel)
        {
            IntPtr t = new IntPtr(excel.Hwnd);   //得到这个句柄,具体作用是得到这块内存入口

            int k = 0;
            GetWindowThreadProcessId(t, out k);    //得到本进程唯一标志k
            System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);    //得到对进程k的引用
            p.Kill();      //关闭进程k
        }

 

posted @ 2009-04-04 19:17 lab 阅读(61) 评论(0) 编辑