复制 GridWeb 行和列
Aspose.Cells.GridWeb 组件提供了在使用 GridCells 类时复制行和列的方法。本文演示了如何使用 Aspose.Cells.GridWeb 公开的 API 在 GridWeb 界面上复制行和列。
GridCells.CopyRow、GridCells.CopyColumn、GridCells.CopyRows 和 GridCells.CopyColumns 方法会将内容、样式和公式从源行和列复制到目标。
复制行和列
如果您还不熟悉 Aspose.Cells.GridWeb 组件,我们强烈建议您检查Aspose.Cells.GridWeb简介和详细的文章如何在 WebForms 应用程序中添加 Aspose.Cells.GridWeb 组件.
复制单行
为了使示例保持简单,本文使用了一个包含一行的现有电子表格和一个对行中所有值求和的简单公式。以下是复制行之前电子表格在 Aspose.Cells.GridWeb 界面中的显示方式。
代码片段很简单,如下所示。它访问活动工作表顺序的 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 在复制行操作后的样子。
复制单列
以下示例使用一个包含一列的现有电子表格和一个对列中所有值求和的简单公式。以下是复制列之前电子表格在 Aspose.Cells.GridWeb 界面中的显示方式。
与上面的示例类似,以下代码片段访问活动工作表顺序的 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 在复制列操作后的样子。
复制多行
还可以在使用 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 在复制行操作前后的样子。
复制多列
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 在复制行操作前后的样子。