我使用ASP.NET和Win2000+IIS5.0构建Web网站。
在服务器上生成Excel文件,提供给客户端用户打印,但服务器上的Excel打开后,进程无法关闭,使得服务器经常发生问题。如何才能关闭Excel进程哪!论坛里有的代码只能工作在Windows应用程序下,不能在Web服务器代码中使用!请各位大虾给个解决方案吧!
实验通过立刻给分!!!!!

解决方案 »

  1.   

    首先把打开的excel对象colse,然后GC.Collect
      

  2.   

    Please use Marshal.ReleaseComObject method.(Decrements the reference count of the supplied runtime callable wrapper) and then you can invoke GC.Collect() and GC.WaitForPendingFinalizers()
      

  3.   

    我目前用的方法是:
    object missing=System.Reflection.Missing.Value; DateTime dtapp1=DateTime.Now;
    Excel.ApplicationClass app=new Excel.ApplicationClass();
    DateTime dtapp2=DateTime.Now; CellSet cs; try
    {
    app.DisplayAlerts=false; Excel.Workbook book=app.Workbooks.Open(filename,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing); cs=ReadExcel((Excel.Worksheet)book.Sheets[1]); book.Close(false,missing,missing);
    }
    finally
    {
    try
    {
    app.Quit();
    }
    finally
    {
    System.Runtime.InteropServices.Marshal.ReleaseComObject(app); foreach(System.Diagnostics.Process process in System.Diagnostics.Process.GetProcessesByName("EXCEL"))
    {
    if(process.StartTime>=dtapp1&&process.StartTime<=dtapp2)
    {
    process.Kill();
    }
    }
    }
    }
      

  4.   

    to:Lostinet(每晚 9:00 见) 你好!你是在Web服务器上运行的吗?
      

  5.   

    to:cuike519(marshal(修练中...)) 刚试过了,不行啊?
    代码执行时不会出错,但没有关闭Excel进程啊???
      

  6.   

    参考--在.NET中杀死Word,Excel等进程:
    http://blog.csdn.net/net_lover/archive/2004/09/14/103676.aspx