示例#1
0
 public bool DeleteExcelSheet(string pExcelPath, string pSheetName, out string pDeleteSheet)
 {
     try
     {
         object objOpt = Missing.Value;
                         //打开一个Excel应用
                         Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
         if (app == null)
         {
             throw new Exception("打开Excel应用时发生错误!");
         }
         app.Visible = false;
         Microsoft.Office.Interop.Excel.Workbooks wbs = app.Workbooks;
         Microsoft.Office.Interop.Excel._Workbook wb  = wbs.Open(pExcelPath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
         wb.EnableAutoRecover = false;
         Microsoft.Office.Interop.Excel.Sheets     shs = wb.Sheets;
         Microsoft.Office.Interop.Excel._Worksheet sh  = (Microsoft.Office.Interop.Excel._Worksheet)shs.get_Item(pSheetName);
         app.DisplayAlerts = false;
         sh.Delete();
         wb.Save();
         pDeleteSheet = string.Empty;
         return(true);
     }
     catch (Exception vErr)
     {
         pDeleteSheet = vErr.Message;
         return(false);
     }
     finally
     {
         KillProcess();
     }
 }