您的位置:首页 > 编程语言 > ASP

C#和Asp.net下调用Excel后无法自动关闭进程的解决方法

2009-02-04 16:46 1061 查看
在ASP.NET中调用EXCEL后(比如导出EXCEL),EXCEL长驻内存的解决办法就是---干掉它!!!

原帖地址: http://hi.baidu.com/cnzynet/blog/item/b7d1a0f22dc00315b17ec50f.html

添加引用:

using System.Runtime.InteropServices;

结束进程代码

[DllImport("user32.dll", CharSet = CharSet.Auto)]

public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int id);

public void KillExcellProcess(string path)

{

Excel.ApplicationClass excel = new Excel.ApplicationClass();//.applicationclass();

excel.Workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

IntPtr t = new IntPtr(excel.Hwnd);

int k = 0;

GetWindowThreadProcessId(t, out k);

System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);

p.Kill();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐