views:

644

answers:

2

I'm trying to delete a worksheet from a excel document from a .Net c# 3.5 application with the interop Excel class (for excel 2003).

I try many things like :

Worksheet worksheet = (Worksheet)workbook.Worksheets[1];
worksheet.Delete();

It's doesn't work and doesn't throw any error ...

+4  A: 

I found why after more that one hour looking for the answer

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

where app is your XlsApplication

Melursus
+3  A: 

It is also important to note that the workbook must contain at least one worksheet; this means you cannot delete all worksheets in a workbook.

Richard Morgan
Yes, that is right, and if you attempt to delete them all, you will get a COMException.
Chris