Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Excel Interop Deleting a worksheet

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 ...

like image 770
Melursus Avatar asked Mar 24 '09 18:03

Melursus


People also ask

How do I delete a sheet in Excel C#?

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

How do you delete an Excel worksheet?

On the Home tab, in the Cells group, click the arrow next to Delete, and then click Delete Sheet. Tip: You can also right-click the sheet tab of a worksheet or a sheet tab of any selected worksheets that you want to delete, and then click Delete Sheet.

How do you delete a worksheet without prompt in Excel VBA?

You can also press ALT + F8 to open the Macro dialog box. ❼ From the Macro dialog box, select the function name of the VBA code and hit Run. This will instantly delete the sheet that you have inserted in the VBA code without showing any prompt warning message.

How do I delete a worksheet in VBA?

To delete a sheet using VBA, you need to use the VBA Delete method. You need to specify the sheet that you want to delete and then use this method. Let's say if you want to delete the “Sheet1”, then you need to mention sheet1 and then type a dot (.) and in the end, type “Delete”.


1 Answers

After more than one hour looking I found the answer:

xlApp.DisplayAlerts = false; worksheet.Delete(); xlApp.DisplayAlerts = true; 
like image 81
Melursus Avatar answered Sep 22 '22 08:09

Melursus