C#操作Excel,调用ApplicationClass.Quit()关闭Excel时,发生异常:Microsoft Office Word 遇到问题需要关闭

应将ApplicationClass.Quit();  放在所有的

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);后面,如:


  if (xlApp != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
                    xlApp = null;
                }

                workBook.Close(falsenullnull);
                xlApp.Workbooks.Close();
                xlApp.Quit();  //自动打开Excel,抛异常

 

 

posted @ 2011-10-21 16:31    阅读(3983)  评论(0编辑  收藏  举报