Copy Rows and Columns

Copying Rows

Copying Single Row

The following example shows how to copy a single row in a worksheet. The example uses a Microsoft Excel spreadsheet as input and copies the first row to the next 10 rows in the same worksheet.

Below is a snapshot of the input spreadsheet.

todo:image_alt_text

After executing the above code snippet, the resultant spreadsheet looks as follow.

todo:image_alt_text

Copying Multiple Rows

You can also copy multiple rows onto a new destination while using the Cells.copyRows method which takes an additional parameter of type integer to specify the number of source rows to be copied.

Below is a snapshot of the input spreadsheet containing 3 rows of data whereas the code snippet provided below copies all 3 rows to a new location starting from 7th row.

todo:image_alt_text

Here is the resultant spreadsheet view after executing the above code snippet.

todo:image_alt_text

Copying Columns

Copying Single Column

The following example shows how to copy a column in a worksheet. This example uses an existing spreadsheet as input to the process and copies the first column to next 10 columns using two different approaches.

Here is how the input spreadsheet looks.

todo:image_alt_text

Here is the view of resultant spreadsheet after executing the above code snippet.

todo:image_alt_text

Copying Multiple Columns

Similar to Cells.copyRows method, the Aspose.Cells APIs also provide the Cells.copyColumns method in order to copy multiple source columns to a new location.

Here is how source and resultant spreadsheets look in Excel.

todo:image_alt_text

todo:image_alt_text