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完全控制搞定了,我#¥#)(×)¥(#。