复制GridWeb行和列

复制行和列

如果您还不熟悉Aspose.Cells.GridWeb组件,我们强烈建议您查看介绍Aspose.Cells.GridWeb如何在WebForms应用程序中添加Aspose.Cells.GridWeb组件的详细文章

复制单行

为了保持示例简单,文章使用一个包含一行和一个简单公式(对该行中所有值求和)的现有电子表格。以下是在复制该行之前,电子表格在Aspose.Cells.GridWeb界面中的显示方式。

todo:image_alt_text

如下所示,代码片段很简单。它访问活动工作表的GridCells对象,以将第一行复制到后续行。

// 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;

在复制行操作之后,Aspose.Cells.GridWeb的外观如何。

todo:image_alt_text

复制单列

以下示例使用包含一列和一个简单公式(对该列中所有值求和)的现有电子表格。以下是在复制该列之前,电子表格在Aspose.Cells.GridWeb界面中的显示方式。

todo:image_alt_text

与上面的示例类似,以下代码段访问活动工作表的GridCells对象,将第一列复制到后续列。

// 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;

在复制列操作之后,Aspose.Cells.GridWeb的外观如何。

todo:image_alt_text

复制多行

在使用GridCells.CopyRows方法复制多行到新目标时,还可以额外提供一个整数类型的参数,以指定要复制的源行数。

// 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;

在复制行操作之前和之后,查看Aspose.Cells.GridWeb的外观。

todo:image_alt_text

todo:image_alt_text

复制多个列

GridCells类还提供CopyColumns方法,额外提供一个整数类型的参数,以指定要复制的源列数。

// 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;

在复制行操作之前和之后,查看Aspose.Cells.GridWeb的外观。

todo:image_alt_text

todo:image_alt_text