Delete A Worksheet

Hi,

Is there any way to remove/delete a worksheet from a workbook?

Hi,

Thanks for considering Aspose.

Well you may use Worksheets.RemoveAt() method for the task.

Here is a sample code.

// Create a new Workbook.
Workbook wb = new Workbook();
// Open an existing excel file.
wb.Open(@"d:\test.xls");
// Create a Worksheets object with reference to 
// the sheets of the Workbook.
Worksheets sheets = wb.Worksheets;
// Remove the sheet named MySheet from an existing
// Worksheets list in the Workbook.
sheets.RemoveAt("MySheet");
// Save the excel file.

wb.Save(@"d:\mybook.xls");

You may also refer:

Managing Worksheets

Regards

Amjad Sahi

Aspose Nanjing Team

Hello guys,

actually i am also trying to delete the sheet from excel workbook but when i am trying to use above method “RemoveAt” it showing RemoeAt is not an attribute of WorkSheets so can you please help lor provide me some documentation link using which, we can solve this error.

Thank you.

@asposeLegit,

Please see the document with example code for your reference.
Manage Worksheets of Microsoft Excel files.|Documentation
Moreover, the method name is RemoveAt and not RemoeAt of WorksheetCollection, so please correct your code.