/// <summary>
/// 根据名称删除工作表
/// </summary>
/// <param name="sheetName"></param>
public void DeleteWorkSheet(string sheetName)
{
try
{
Excel.Worksheet sheet = null;
//找到名称位sheetName的工作表
for(int i=1;i<=this.WorkSheetCount;i++)
{
workSheet = (Excel.Worksheet)workBook.Sheets.get_Item(i);
if(workSheet.Name == sheetName)
{
sheet = workSheet;
}
}
if(sheet != null)
{
sheet.Delete();
}
else
{
this.KillExcelProcess();
throw new Exception("名称为\"" + sheetName + "\"的工作表不存在");
}
}
catch(Exception e)
{
this.KillExcelProcess();
throw e;
}
}
/// <summary>
/// 根据索引删除工作表
/// </summary>
/// <param name="sheetIndex"></param>
public void DeleteWorkSheet(int sheetIndex)
{
if(sheetIndex > this.WorkSheetCount)
{
this.KillExcelProcess();
throw new Exception("索引超出范围,WorkSheet索引不能大于WorkSheet数量!");
}
try
{
Excel.Worksheet sheet = null;
sheet = (Excel.Worksheet)workBook.Sheets.get_Item(sheetIndex);
sheet.Delete();
}
catch(Exception e)
{
this.KillExcelProcess();
throw e;
}
}