110,549
社区成员
发帖
与我相关
我的任务
分享
//*** Kill Excel Process ***//
[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int lpdwProcessID);
public static void KillExcellProcess(Microsoft.Office.Interop.Excel.Application xlsApp)
{
try
{
if (xlsApp != null)
{
int excelProcessID = 0;
GetWindowThreadProcessId(new IntPtr(xlsApp.Hwnd), out excelProcessID);
if (excelProcessID != 0)
{
Process excelProc = Process.GetProcessById(excelProcessID);
if (excelProc != null)
{
excelProc.Kill();
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}