Skip to main content
A newer version of this page is available. .

How to: Add a New Row or Column to a Worksheet

  • 3 minutes to read

Row

This example demonstrates how to insert new rows into a worksheet. You can do this in the following ways.

  • Use the Row.Insert method.
  • Call the RowCollection.Insert method of the object accessed via the Worksheet.Rows property. To specify where a new row should be inserted, pass a zero-based row index to the method as a parameter. To insert multiple rows, pass the number of rows to be inserted as well.
  • To insert empty rows above the specified range of cells, use the Worksheet.InsertCells method with the cell range and InsertCellsMode.EntireRow enumeration member passed as parameters. This method inserts the same number of rows that contains the specified cell range.
// Insert a new row 3.
worksheet.Rows["3"].Insert();

// Insert a new row into the worksheet at the 5the position.
worksheet.Rows.Insert(4);

// Insert five rows into the worksheet at the 9th position.
worksheet.Rows.Insert(8, 5);

// Insert two rows above the "L15:M16" cell range.
worksheet.InsertCells(worksheet.Range["L15:M16"], InsertCellsMode.EntireRow);

Note

The number of rows in a worksheet is permanently fixed - 1048576.

Column

This example demonstrates how to insert new columns into a worksheet. You can do this in the following ways.

  • Use the Column.Insert method.
  • Call the ColumnCollection.Insert method of the object accessed via the Worksheet.Columns property. To specify where a new column should be inserted, pass a zero-based column index to the method as a parameter. To insert multiple columns, pass the number of columns to be inserted as well.
  • To insert empty columns to the left of the specified range of cells, use the Worksheet.InsertCells method with the cell range and InsertCellsMode.EntireColumn enumeration member passed as parameters. This method inserts the same number of columns that comprising the specified cell range.
// Insert a new column C.
worksheet.Columns["C"].Insert();

// Insert a new column into the worksheet at the 5th position.
worksheet.Columns.Insert(4);

// Insert three columns into the worksheet at the 7th position.
worksheet.Columns.Insert(6, 3);

// Insert two columns to the left of the "L15:M16" cell range.
worksheet.InsertCells(worksheet.Range["L15:M16"], InsertCellsMode.EntireColumn);

Note

The number of columns in a worksheet is permanently fixed - 16384.

See Also