插入行和列
Contents
[
Hide
]
本主题说明如何使用 Aspose.Cells.GridWeb API 将新行和列插入到工作表中。可以在工作表中的任何位置插入行或列。
插入行
要在工作表中的任意位置插入一行:
- 将 Aspose.Cells.GridWeb 控件添加到 Web 窗体。
- 访问要向其添加行的工作表。
- 通过指定要插入行的行索引来插入行。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Get row index entered by user | |
int rowIndex = Convert.ToInt16(txtRowIndex.Text.Trim()); | |
// Add row at specified index | |
sheet.Cells.InsertRow(rowIndex); |
插入列
要在工作表中的任意位置插入一列:
- 将 Aspose.Cells.GridWeb 控件添加到 Web 窗体。
- 访问要向其添加列的工作表。
- 通过指定要插入列的列索引来插入列。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Get column index entered by user | |
int columnIndex = Convert.ToInt16(txtColumnIndex.Text.Trim()); | |
// Add column at specified index | |
sheet.Cells.InsertColumn(columnIndex); |
您还可以使用 InsertRows/InsertColumns 方法将多个行/列相应地插入到工作表中。