Back to Devexpress

How to: Insert a Cell or Cell Range

windowsforms-15403-controls-and-libraries-spreadsheet-examples-cells-how-to-insert-a-cell-or-cell-range.md

latest2.1 KB
Original Source

How to: Insert a Cell or Cell Range

  • Apr 22, 2022

This example demonstrates how to insert cells into a worksheet. To do this, use the Worksheet.InsertCells method. Pass a cell or cell range where you want to insert new cells, and the InsertCellsMode.ShiftCellsDown or InsertCellsMode.ShiftCellsRight enumeration member to specify how to shift other cells.

csharp
using DevExpress.Spreadsheet;
// ...

IWorkbook workbook = spreadsheetControl1.Document;
Worksheet worksheet = workbook.Worksheets[0];

// Insert a cell into the C5 position, shifting other cells in the same column down.
worksheet.InsertCells(worksheet.Cells["C5"], InsertCellsMode.ShiftCellsDown);

// Insert cells into the location of the H11:I12 range, shifting other cells in the same row to the right.
worksheet.InsertCells(worksheet.Range["H11:I12"], InsertCellsMode.ShiftCellsRight);
vb
Imports DevExpress.Spreadsheet
' ...

Dim workbook As IWorkbook = spreadsheetControl1.Document
Dim worksheet As Worksheet = workbook.Worksheets(0)

' Insert a cell into the C5 position, shifting other cells in the same column down.
worksheet.InsertCells(worksheet.Cells("C5"), InsertCellsMode.ShiftCellsDown)

' Insert cells into the location of the H11:I12 range, shifting other cells in the same row to the right.
worksheet.InsertCells(worksheet.Range("H11:I12"), InsertCellsMode.ShiftCellsRight)

See Also

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

Cells and Cell Ranges