/// <summary>
/// 在指定名称的工作表后面拷贝指定个数的该工作表的副本,并重命名
/// </summary>
/// <param name="sheetName">工作表名称</param>
/// <param name="sheetCount">工作表个数</param>
public void CopyWorkSheets(string sheetName,int sheetCount)
{
try
{
Excel.Worksheet sheet = null;
int sheetIndex = 0;
for(int i=1;i<=this.WorkSheetCount;i++)
{
workSheet = (Excel.Worksheet)workBook.Sheets.get_Item(i);
if(workSheet.Name == sheetName)
{
sheet = workSheet;
sheetIndex = workSheet.Index;
}
}
if(sheet != null)
{
for(int i=sheetCount;i>=1;i--)
{
sheet.Copy(this.missing,sheet);
}
//重命名
for(int i=sheetIndex;i<=sheetIndex+sheetCount;i++)
{
workSheet = (Excel.Worksheet)workBook.Sheets.get_Item(i);
workSheet.Name = sheetName + "-" + Convert.ToString(i - sheetIndex + 1);
}
}
else
{
this.KillExcelProcess();
throw new Exception("名称为\"" + sheetName + "\"的工作表不存在");
}
}
catch(Exception e)
{
this.KillExcelProcess();
throw e;
}
}