Copy Worksheets within a Workbook
Contents
[
Hide
]
Aspose.Cells provides an overloaded method, Aspose.Cells.WorksheetCollection.AddCopy(), that is used to add a worksheet to the collection and copies data from an existing worksheet. One version of the method takes the index of the source worksheet as a parameter. The other version takes the name of the source worksheet as the parameter.
The following example shows how to copy an existing worksheet within a workbook.
//Create a new Workbook.
//Open an existing Excel file.
Workbook wb = new Workbook("ResultedBook.xls");
//Create a Worksheets object with reference to
//the sheets of the Workbook.
WorksheetCollection sheets = wb.Worksheets;
//Copy data to a new sheet from an existing
//sheet within the Workbook.
sheets.AddCopy("MySheet");
//Save the Excel file.
wb.Save("Copy Worksheet.xls");