Back to Devexpress

How to: Delete a Worksheet

windowsforms-15362-controls-and-libraries-spreadsheet-examples-worksheets-how-to-delete-a-worksheet.md

latest2.3 KB
Original Source

How to: Delete a Worksheet

  • Dec 09, 2022

This example demonstrates how to remove a worksheet from a workbook by calling the WorksheetCollection.Remove or WorksheetCollection.RemoveAt method of the WorksheetCollection object that is accessed via the IWorkbook.Worksheets property.

View Example

csharp
// Delete the "Sheet2" worksheet from the workbook.
workbook.Worksheets.Remove(workbook.Worksheets["Sheet2"]);

// Delete the first worksheet from the workbook.
workbook.Worksheets.RemoveAt(0);
vb
' Delete the "Sheet2" worksheet from the workbook.
workbook.Worksheets.Remove(workbook.Worksheets("Sheet2"))

' Delete the first worksheet from the workbook.
workbook.Worksheets.RemoveAt(0)

You can also hide a worksheet. See the How to: Show and Hide a Worksheet topic for details.

Note

A workbook must always contain at least one visible worksheet.

The SpreadsheetControl.SheetRemoved event is raised after a worksheet has been deleted from the workbook via the control’s UI.

See Also

How to: Show and Hide a Worksheet

How to: Add a New Worksheet

Worksheets in Spreadsheet Documents