System.Runtime.InteropServices.Marshal.ReleaseComObject(wSheet);
            
            wBook.Close(true, strFilePath, System.Reflection.Missing.Value);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(wBook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(wBooks);
            xlApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
我做了以上步骤,但发现进程里面excel有N个 excel.exe! 
       

解决方案 »

  1.   

    理论上是还有对excel的引用 实际上是 我也搞不出来 同问
      

  2.   


    遍历进程
    然后
    Process.kill
      

  3.   

     public void PreExitExcel()
            {
                System.Diagnostics.Process[] allProcess = System.Diagnostics.Process.GetProcesses();
                foreach (System.Diagnostics.Process thisprocess in allProcess)
                {
                    string processName = thisprocess.ProcessName;
                    if (processName.ToLower() == "excel")
                    {
                        try
                        {
                            thisprocess.Kill();
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                            return;
                        }
                    }
                }
            }
      

  4.   

    LZ以上代码是 关闭名为excel的进程
      

  5.   

    需要添加引用com中的"microsoft excel 11.0 object library"//关闭excel进程
    Microsoft.Office.Interop.Excel.Application xlapp = new Microsoft.Office.Interop.Excel.Application();
                    if (xlapp != null)
                    {
                        xlapp.Quit();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlapp);
                        foreach (System.Diagnostics.Process theProc in System.Diagnostics.Process.GetProcessesByName("EXCEL"))
                        {
                            //先关闭图形窗口。如果关闭失败...有的时候在状态里看不到图形窗口的excel了,  
                            //但是在进程里仍然有EXCEL.EXE的进程存在,那么就需要杀掉它:p  
                            if (theProc.CloseMainWindow() == false)
                            {
                                theProc.Kill();
                            }
                        }
                        xlapp = null;
                    }
      

  6.   

        [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]        public static extern int SetProcessWorkingSetSize(IntPtr process,            int minSize,            int maxSize);        /// <summary>          /// 释放内存          /// </summary>          public static void ClearMemory()
            {            GC.Collect();            GC.WaitForPendingFinalizers();            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {                Man.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);            }        }