很简单的一个程序,就是要删除excel文件中的指定sheet. 如果该excel文件只有一个sheet,那么将该sheet更名为"Test",否则删除该sheet.  现在运行的情况是,如果excel中不只一个sheet,则删除成功,结束后,服务器端的excel进程自动结束.  但是,如果只有一个sheet,改完名后,excel进程还在内存中. 虽然打开excel文件查看,唯一的sheet已经更名为Test.问题出在哪里????
        /// <summary>
    /// 从当前打开的excel中删除一个sheet
    /// </summary>
    /// <param name="strSheetName">要删除的sheet的名称</param>
    /// <returns>删除成功与否</returns>
    public static bool DeleteWorksheet(string strFileName,string strSheetName)
    {
        if(! (System.IO.File.Exists(strFileName)) )
        {
            return false;//如果Excel文件不存在,直接返回
        }
        
        Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
        object missing = System.Reflection.Missing.Value;
        Microsoft.Office.Interop.Excel.Workbook workbook = ExcelApp.Workbooks.Open(strFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);        //ExcelApp.DisplayAlerts = false;
        try
        {
            if ((ExcelApp != null) && (ExcelApp.ActiveWorkbook != null))
            {
                Microsoft.Office.Interop.Excel.Sheets sheets = workbook.Worksheets;
                int iCnt = sheets.Count;                if (iCnt == 1)
                {
                    Microsoft.Office.Interop.Excel._Worksheet wksheet = (Microsoft.Office.Interop.Excel._Worksheet)sheets.get_Item(1);                    
                    wksheet.Name = "Test";
                }else{
                    for (int i = 0; i < iCnt; i++)
                    {
                        Microsoft.Office.Interop.Excel._Worksheet wksheet = (Microsoft.Office.Interop.Excel._Worksheet)sheets.get_Item(i + 1);
                        if (wksheet.Name == strSheetName)
                        {
                            wksheet.Delete();
                            break;
                        }
                    }
                }            }
            
            //ExcelApp.DisplayAlerts = true;
            ExcelApp.ActiveWorkbook.Save();
            ExcelApp.Workbooks.Close();
            ExcelApp.Quit();
            ExcelApp = null;
            return true;
        }
        catch
        {
            ExcelApp.ActiveWorkbook.Save();
            ExcelApp.Workbooks.Close();
            ExcelApp.Quit();
            return false;
        }
    }兄弟们,只剩70分了。