日期:2014-05-17 浏览次数:20466 次
if (excelApp != null)ReleaseComObject不能关闭进程
{
//Marshal.ReleaseComObject(excelApp);
excelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
//KillExcel(excelApp);
excelApp = null;
}
private static void KillExcel(Microsoft.Office.Interop.Excel.Application theApp)p.Kill();会报拒绝访问错误
{
int id = 0;
IntPtr intptr = new IntPtr(theApp.Hwnd);
System.Diagnostics.Process p = null;
try
{
GetWindowThreadProcessId(intptr, out id);
p = System.Diagnostics.Process.GetProcessById(id);
if (p != null)
{
p.Kill();
p.WaitForExit();
p.Dispose();
}
}
catch (Exception ex)
{
}
}