Copy Sheet Within Workbook
Contents
[
Hide
]
Microsoft Excel - Moving or Copying Sheets within Workbook
Following are the steps involved for copying and moving worksheets within or between workbooks.
- To move or copy sheets within or between workbooks, open the workbook that will receive the sheets.
- Switch to the workbook that contains the sheets you want to move or copy, and then select the sheets.
- On the Edit menu, click Move or Copy Sheet.
- In the To book box, click the workbook to receive the sheets.
- To move or copy the selected sheets to a new workbook, click new book.
- In the Before sheet box, click the sheet before which you want to insert the moved or copied sheets.
- To copy the sheets instead of moving them, select the Create a copy check box.
Aspose.Cells - Copy Sheet Within Workbook
Aspose.Cells provides an overloaded method, WorksheetCollection.addCopy(), that is used to add a worksheet to the collection and copy 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.
The following example shows how to copy an existing worksheet within a workbook.
Copy sheets using Aspose.Cells
Java
//Create a new Workbook by excel file path
Workbook wb = new Workbook(dataDir + "workbook.xls");
//Create a Worksheets object with reference to the sheets of the Workbook.
WorksheetCollection sheets = wb.getWorksheets();
//Copy data to a new sheet from an existing sheet within the Workbook.
sheets.addCopy("Sheet1");
Apache POI SS - Copy Sheet Within Workbook
Workbook.cloneSheet() is used to to copy sheets with workbook.
Copy sheets using Apache POI SS
Java
Workbook wb = new HSSFWorkbook();
wb.createSheet("new sheet");
wb.createSheet("second sheet");
Sheet cloneSheet = wb.cloneSheet(0);
Download Running Code
Download Sample Code
For more details, visit Copying and Moving Worksheets.