Back to Devexpress

Row.Insert() Method

officefileapi-devexpress-dot-spreadsheet-dot-row-79002e5d.md

latest6.6 KB
Original Source

Row.Insert() Method

Inserts a new row into the worksheet.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void Insert()
vb
Sub Insert

Remarks

Use the Insert method to add a new row above the current row. To add more than one row, use the RowCollection.Insert method.

Note

The number of rows in a worksheet is unchanged - 1,048,576. When you add new rows, the equivalent number of rows at the end are automatically removed from the worksheet.

To copy data (for example, values, formulas, formatting, etc.) from one row to another one, use the CellRange.CopyFrom method. For details, see the How to: Copy a Row or Column example.

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

csharp
// 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);
vb
' 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() 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.

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/RowAndColumnActions.cs#L28

csharp
// Insert a new row 3.
worksheet.Rows["3"].Insert();

wpf-spreadsheetcontrol-api-part-1/CS/SpreadsheetControl_WPF_API/SpreadsheetActions/RowAndColumnActions.cs#L29

csharp
// Insert a new row 3.
worksheet.Rows["3"].Insert();

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.cs#L30

csharp
// Insert the third row.
worksheet.Rows["3"].Insert();

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/RowAndColumnActions.vb#L32

vb
' Insert a new row 3.
worksheet.Rows("3").Insert()

wpf-spreadsheetcontrol-api-part-1/VB/SpreadsheetControl_WPF_API/SpreadsheetActions/RowAndColumnActions.vb#L32

vb
' Insert a new row 3.
worksheet.Rows("3").Insert()

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.vb#L28

vb
' Insert the third row.
worksheet.Rows("3").Insert()
' Insert the fifth row.

See Also

Insert

InsertCells

Rows and Columns in Spreadsheet Documents

Row Interface

Row Members

DevExpress.Spreadsheet Namespace