How to delete worksheets from Excel workbook in C#?

Tripati Subudhi picture Tripati Subudhi · Sep 13, 2011 · Viewed 9.9k times · Source

Let's say I have one workbook which is having 6 sheets as Sheet1, Sheet2, Sheet3, Sheet4, Sheet5, Sheet6.

So from here I want to delete Sheet1, Sheet2, Sheet3. How can I do that?

Answer

VMAtm picture VMAtm · Sep 13, 2011

You can call the .Delete() method, like that:

Globals.Sheet1.Delete();

Update, according your comment:

Excel._Worksheet ws = (Excel._Worksheet)app.Workbooks[i].Worksheets[j];
ws.Delete();