Free Support Forum - aspose.com

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:

http://www.aspose.com/Wiki/default.aspx/Aspose.Cells/ManagingWorksheets.html

Regards

Amjad Sahi

Aspose Nanjing Team