delete excel worksheets programmatically

后端 未结 2 1289
鱼传尺愫
鱼传尺愫 2021-01-18 06:02

I have an excel workbook with many, many sheets. I want to delete all the sheets except for three of them.

Specifically, i would like to know if there is a way to re

相关标签:
2条回答
  • 2021-01-18 06:35
    xlApp.DisplayAlerts = false;
    for (int i = xlApp.ActiveWorkbook.Worksheets.Count; i > 0 ; i--)
    {
        Worksheet wkSheet = (Worksheet)xlApp.ActiveWorkbook.Worksheets[i];
        if (wkSheet.Name == "NameOfSheetToDelete")
        {
            wkSheet.Delete();
        }
    }
    xlApp.DisplayAlerts = true;
    
    0 讨论(0)
  • 2021-01-18 06:40

    I know this is old but I just use the fallowing

    workBook.Sheets["Sheet1"].Delete();

    0 讨论(0)
提交回复
热议问题