Copy GridWeb Rows and Columns

Copying Rows & Columns

If you are not already acquainted with Aspose.Cells.GridWeb component, we strongly suggest you to check the Introduction to Aspose.Cells.GridWeb and detailed article on How to add Aspose.Cells.GridWeb component in a WebForms application.

Copying Single Row

In order to keep the example simple, the article uses an existing spreadsheet with one row and a simple formula that sums all the values in the row. Here is how the spreadsheet is displayed in the Aspose.Cells.GridWeb interface before copying the row.

todo:image_alt_text

The code snippet is simple as demonstrated below. It accesses GridCells object of active worksheet order to make a copy of the first row to the subsequent row.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Get the instance of active GridWorksheet
var activeSheet = GridWeb1.ActiveSheet;
// Copy first row to next row
activeSheet.Cells.CopyRow(activeSheet.Cells, 0, 1);
Label1.Text = "Row 1 copied to row 2 in worksheet " + activeSheet.Name;

Here is how the Aspose.Cells.GridWeb looks after copy row operation.

todo:image_alt_text

Copying Single Column

The following example uses an existing spreadsheet with one column and a simple formula that sums all the values in the column. Here is how the spreadsheet is displayed in the Aspose.Cells.GridWeb interface before copying the column.

todo:image_alt_text

Similar to the above example, the following code snippet accesses the GridCells object of active worksheet order to make a copy of the first column to the subsequent column.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Get the instance of active GridWorksheet
var activeSheet = GridWeb1.ActiveSheet;
// Copy first column to next column
activeSheet.Cells.CopyColumn(activeSheet.Cells, 0, 1);
Label1.Text = "Column 1 copied to column 2 in worksheet " + activeSheet.Name;

Here is how the Aspose.Cells.GridWeb looks after copy column operation.

todo:image_alt_text

Copying Multiple Rows

It is also possible to copy multiple rows to a new destination while using the GridCells.CopyRows method, which takes an additional parameter of type integer to specify the number of source rows to be copied.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Get the instance of active GridWorksheet
var activeSheet = GridWeb1.ActiveSheet;
// Copy first 3 rows to 7th row
activeSheet.Cells.CopyRows(activeSheet.Cells, 0, 6, 3);
Label1.Text = "Rows 1 to 3 copied to rows 7 to 9 in worksheet " + activeSheet.Name;

Here is how Aspose.Cells.GridWeb look before & after copy rows operation.

todo:image_alt_text

todo:image_alt_text

Copying Multiple Columns

The GridCells class also provide the CopyColumns method, which takes an additional parameter of type integer to specify the number of source columns to be copied.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Get the instance of active GridWorksheet
var activeSheet = GridWeb1.ActiveSheet;
// Copy first 3 column to 7th column
activeSheet.Cells.CopyColumns(activeSheet.Cells, 0, 6, 3);
Label1.Text = "Columns 1 to 3 copied to columns 7 to 9 in worksheet " + activeSheet.Name;

Here is how Aspose.Cells.GridWeb look before & after copy rows operation.

todo:image_alt_text

todo:image_alt_text