web.config
=============
<identity impersonate="true" username="superadmin" password="123456"/>
=============
PrintExcel.class中
==================try
''''打开Excel文件
myApp = New Excel.Application
With myApp '11111
     .Workbooks.Open("D:\PlS\Template\BAOJIADAN.XLT")
     .Visible = False
End With '11111
mySheet = myApp.Sheets(1)
....

''''打开Excel文件
........

''''打开Excel文件


'''''关闭Excel文件

myApp.ActiveWorkbook.Close(False)
myApp.Quit()
myApp = Nothing
mySheet = Nothing
''''关闭Excel文件
Catch ex As Exception
       sMsg = Err.Description & "[" & Err.Number & "]"
       Return sMsg
Finally
       MemoryClear()
End Try #Region "清理生成的相关资源 "
        Protected Sub MemoryClear()
            If TypeName(myApp) <> "Nothing" Then myApp.Quit()
            If TypeName(myApp) <> "Nothing" Then System.Runtime.InteropServices.Marshal.ReleaseComObject(myApp)
            If TypeName(mySheet) <> "Nothing" Then System.Runtime.InteropServices.Marshal.ReleaseComObject(mySheet)
            If TypeName(myBook) <> "Nothing" Then System.Runtime.InteropServices.Marshal.ReleaseComObject(myBook)
            myBook = Nothing
            mySheet = Nothing
            myApp = Nothing
            GC.Collect()
        End Sub
#End Region这样还关闭不了。!!!!

解决方案 »

  1.   

    //清除excel
    objExcel.Workbooks.Close();
    objExcel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject (objExcel);
    System.Runtime.InteropServices.Marshal.ReleaseComObject (objExcel); objWork=null;
    objExcel = null; GC.Collect();
      

  2.   

    //清除excel
    objExcel.Workbooks.Close();
    objExcel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject (objExcel);
    System.Runtime.InteropServices.Marshal.ReleaseComObject (objExcel); objWork=null;
    objExcel = null; GC.Collect();
    =========================================================
    还是退不掉。
      

  3.   

    写一个关闭excel的函数在调用excel前后使用
    Public Sub KillExcel()
            
    Dim pList() As Process = Process.GetProcessesByName("Excel")
           
     For Each proc As Process In pList
                
    proc.Kill()
            
    Next
        
    End Sub
      

  4.   

    objWork=null;
    objExcel = null;GC.Collect();
    ------------------
    正解
      

  5.   

    kelerfang 正解 应该找到excel的进程,然后关掉进程
      

  6.   

    我也遇到过
    我是在Finally里把所有要用到的connection command
    等资源全都释放掉就好了