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

Asp.net 操作Excel 无法关闭解决方法之一

2009-02-05 22:47 281 查看
if (range != null)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(range);
range = null;
}
catch (Exception e1)
{
}
}

if (worksheet != null)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
worksheet = null;
}
catch (Exception e2)
{
}
}
if (workbook != null)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
workbook = null;
}
catch (Exception e3)
{
}
}
if (workbooks != null)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbooks);
workbook = null;
}
catch (Exception e3)
{
}
}
try
{

KillExcelProcess(xlApp.Hwnd);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
if (xlApp != null)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
xlApp = null;
}
catch (Exception e4)
{
}
}

GC.Collect();

这种方式经常关闭不了Excel,苦熬几个小时,测试无数,最后将站点中的bin目录中的excel.dll的security添加了everyone完全控制搞定了,我#¥#)(×)¥(#。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐