Copying and Moving Worksheets in PHP

Aspose.Cells - Copying and Moving Worksheets

Copy Worksheets within a Workbook

To copy a worksheet using Aspose.Cells for Java in PHP, call the copy_worksheet method of the copyworksheets module. Below you can see a code example.

PHP Code

# Create a Worksheets object with reference to the sheets of the Workbook.
$sheets = $workbook->getWorksheets();

# Copy data to a new sheet from an existing sheet within the Workbook.
$sheets->addCopy("Sheet1");

# Saving the modified Excel file in default (that is Excel 2003) format
$workbook->save($dataDir . "Copy Worksheet.xls");

Move Worksheets within a Workbook

To move a worksheet using Aspose.Cells for Java in PHP, call the move_worksheet method of the copyworksheets module. Below you can see a code example.

PHP Code

# Get the first worksheet in the book.
$sheet = $workbook->getWorksheets()->get(0);

# Move the first sheet to the third position in the workbook.
$sheet->moveTo(2);

# Saving the modified Excel file in default (that is Excel 2003) format
$workbook->save($dataDir . "Move Worksheet.xls");

Download Running Code

Download Copying and Moving Worksheets (Aspose.Cells) from any of the below‑mentioned social coding sites: