Insert Rows and Columns

Inserting Rows

To insert a row at any position in a worksheet:

  1. Add the Aspose.Cells.GridWeb control to the Web Form.
  2. Access the worksheet you’re adding rows to.
  3. Insert a row by specifying a row index where the row would be inserted.
// 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);

Inserting Columns

To insert a column at any position in a worksheet:

  1. Add the Aspose.Cells.GridWeb control to a Web Form.
  2. Access the worksheet you’re adding columns to.
  3. Insert a column by specifying the column index where the column would be inserted.
// 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);