#region 结束EXCEL.EXE进程的方法 /// <summary> /// 结束EXCEL.EXE进程的方法 /// </summary> /// <param name="m_objExcel">EXCEL对象</param> [DllImport("user32.dll", SetLastError = true)] static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId); private static void KillSpecialExcel(Microsoft.Office.Interop.Excel.Application m_objExcel) { try { if (m_objExcel != null) { int lpdwProcessId; GetWindowThreadProcessId(new IntPtr(m_objExcel.Hwnd), out lpdwProcessId); System.Diagnostics.Process.GetProcessById(lpdwProcessId).Kill(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } #endregion