officefileapi-12087-spreadsheet-document-api-examples-rows-and-columns-how-to-add-a-new-row-or-column-to-a-worksheet.md
This example demonstrates how to insert new rows into a worksheet.
Enclose your code in the Workbook.BeginUpdate - Workbook.EndUpdate method calls to improve performance when you add multiple rows to a document.
// 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);
' 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.
This example demonstrates how to insert new columns into a worksheet.
Enclose your code in the Workbook.BeginUpdate - Workbook.EndUpdate method calls to improve performance when you add multiple columns to a document.
// 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);
' 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