如何结束Excel进程,为什么运行后多了一个excel进程

解决方案 »

  1.   

    oWB.Close(null,null,null);
    oXL.Workbooks.Close();
    oXL.Quit();
    System.Runtime.InteropServices.Marshal.ReleaseComObject (oRng);
    System.Runtime.InteropServices.Marshal.ReleaseComObject (oXL);
    System.Runtime.InteropServices.Marshal.ReleaseComObject (oSheet);
    System.Runtime.InteropServices.Marshal.ReleaseComObject (oWB);
    oSheet=null;
    oWB=null;
    oXL = null;
    GC.Collect();
      

  2.   

    Dim myProcess As Process
            Dim myProcesses As Process()
            Dim myProcessesName As String        myProcessesName = "Excel"
            If myProcessesName.ToString <> "" Then
                myProcesses = System.Diagnostics.Process.GetProcesses()
                For Each myProcess In myProcesses                If myProcess.ProcessName = myProcessesName Then   'Apsprp
                        myProcess.Kill()
                    End If
                Next
            End If
      

  3.   

    System.Runtime.InteropServices.Marshal.ReleaseComObject ();
    System.Runtime.InteropServices.Marshal.ReleaseComObject ();
    System.Runtime.InteropServices.Marshal.ReleaseComObject ();
    System.Runtime.InteropServices.Marshal.ReleaseComObject ();
    再加垃圾回收,速度很快
      

  4.   

    Public Sub killExcelProcess()
            '结束 Excel 进程
            Dim xlProcess As New System.Diagnostics.Process        For Each xlProcess In System.Diagnostics.Process.GetProcesses
                If xlProcess.ProcessName.ToUpper.Equals("EXCEL") Then
                    '结束 excel 进程 
                    xlProcess.Kill()
                End If
            Next
        End Sub