Skip to main content
Row

RowCollection.Insert(Int32) Method

Inserts a new row into the worksheet at the specified position.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v23.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

void Insert(
    int index
)

Parameters

Name Type Description
index Int32

A zero-based index of the row to insert. If it is negative or exceeds the last available index (1048575), an exception occurs.

Remarks

The number of rows in a worksheet does not change—1,048,576. When you add new rows, the rows below are shifted down and an equivalent number of rows at the end of the worksheet is removed.

Example

This example demonstrates how to insert new rows into a worksheet.

  • Use the Row.Insert method to add a new row above the current row.
  • Call the RowCollection.Insert method of the Worksheet.Rows collection to insert a row at the specified position or add multiple rows at once.
  • To insert empty rows above the specified cell range, use the Worksheet.InsertCells method with the InsertCellsMode.EntireRow enumeration member passed as a parameter. This method inserts the same number of rows as the specified cell range contains.

Enclose your code in the Workbook.BeginUpdate - Workbook.EndUpdate method calls to improve performance when you add multiple rows to a document.

View Example

// 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);

The following code snippets (auto-collected from DevExpress Examples) contain references to the Insert(Int32) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also