Crear workbook/remove sheets

Hello,

What is the proper way to clear a workbook and remove all worksheets (using syncfusion:SfSpreadsheet wpf)?

I’m using the following code; however, the worksheets still remain in the workbook.

 for (int i = DataGridControl.Workbook.Worksheets.Count - 1; i > 1; i--)

 {

     var sheet = DataGridControl.Workbook.Worksheets[i];

     DataGridControl.Workbook.Worksheets.Remove(sheet);

 }


Regards,

Vadim


3 Replies

RC Raj Clinton Gnanaprakasam Syncfusion Team January 6, 2026 02:39 PM UTC

Hi Vadim,

We have reviewed your query. In SfSpreadsheet, you can remove worksheets from the workbook using the RemoveSheet method.
Please find the code snippet below.
for (int i = spreadsheet.Workbook.Worksheets.Count-1; i > 0; i--)
{
    var sheet = spreadsheet.Workbook.Worksheets[i];
    spreadsheet.RemoveSheet(sheet.Name);
}
We have attached a sample for your reference.
Please refer to the user guide below for more details.

Please let us know if you need any further assistance.

Regards,
Raj Clinton G

Attachment: WpfApp1_64cebae9.zip


VA Vadim January 6, 2026 02:57 PM UTC

Hello Raj,

Is there a way to disable the confirmation dialog ?Image_8558_1767711419992



RC Raj Clinton Gnanaprakasam Syncfusion Team January 7, 2026 11:03 AM UTC

Hi Vadim,

We have reviewed your query. You can disable the message box in SfSpreadsheet by setting DisplayAlerts to false.
Please find the code snippet below.
spreadsheet.DisplayAlerts = false;
We have attached a modified sample for your reference.
Please let us know if you need any further assistance.

Regards,
Raj Clinton G

Attachment: WpfApp1_757cbe4e.zip

Loader.
Up arrow icon