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();
}
原帖地址: 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();
}
相关文章推荐
- 【C#】对异步请求处理程序IHttpAsyncHandler的理解和分享一个易用性封装 【手记】走近科学之为什么明明实现了IEnumerable<T>的类型却不能调用LINQ扩展方法 【手记】手机网页弹出层后屏蔽底层的滑动响应 【手记】ASP.NET提示“未能创建类型”处理 【Web】一个非常简单的移动web消息框 【手记】解决EXCEL跑SQL遇“查询无法运行或数据库表无法打开...”
- C#调用Excel后无法退出Excel进程的解决方法
- ASP.NET调用Excel不能结束进程的解决方法
- 关于ASP.NET中调用Excel组件不能结束进程的解决方法
- 关于ASP.NET中调用Excel组件不能结束进程的解决方法
- Asp.Net异常:"由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值"的解决方法
- C# ASP.NET Webservice调用外部exe无效的解决方法
- C#窗体程序,当窗口关闭后,进程无法关闭解决方法
- C# 调用Office Excel 接口方法Quit(),但是Excel进程不退出的解决办法
- ASP.NET导出Excel时长数字自动使用科学计数法的解决方法
- Asp.Net异常:"由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值"的解决方法
- Asp.Net异常:"由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值"的解决方法
- 【转】.NET引用Excel操作时无法关闭Excel.exe进程的解决方法
- Asp.Net异常:"由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值"的解决方法
- C# ASP.NET Webservice调用外部exe无效的解决方法
- ASP.NET(C#) 读取EXCEL另加解决日期问题的方法分享
- EXTASPNET C# ASP.NET sql server 调用存储过程超时,解决方法
- asp.net+C# 服务器安装篇--无法更新数据库 *.MDF,因为数据库是只读的解决方法
- 【.Net码农】Asp.Net异常:"由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值"的解决方法
- C# ASP.NET Webservice调用外部exe无效的解决方法