Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete worksheets from Excel workbook in C#?

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?

like image 728
Tripati Subudhi Avatar asked Sep 13 '11 12:09

Tripati Subudhi


2 Answers

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();
like image 182
VMAtm Avatar answered Oct 31 '22 13:10

VMAtm


I hope this code will help you:

app.DisplayAlerts = false; 
worksheet.Delete(); 
app.Displayalerts = true;

where app is your XlsApplication.

like image 33
ranga nathan Avatar answered Oct 31 '22 13:10

ranga nathan