C# 操作excel 关闭excel的方法

[DllImport("user32.dll",SetLastError=true)]

static extern int GetWindowThreadProcessId(IntPtr hwnd,out int processid);

调用方法:

Microsoft.office.Interop.Excel.Application exeApp = new Microsoft.office.Interop.Excel.Application();

//各种excel操作

exeApp.Visible = False;

//

if(exeApp != null)

{

  exeApp.Quit();

  int pid;

  GetWindowThreadProcessId(new IntPtr(exeApp.Hwnd),out pid);

  System.Diagnostics.Process.GetProcessById(pid).Kill();

}

原文地址:https://www.cnblogs.com/zhangxiaoshuai/p/5870694.html