复制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的外观。