Back to Devexpress

Worksheet.InsertCells(CellRange) Method

officefileapi-devexpress-dot-spreadsheet-dot-worksheet-dot-insertcells-x28-devexpress-dot-spreadsheet-dot-cellrange-x29.md

latest4.5 KB
Original Source

Worksheet.InsertCells(CellRange) Method

Inserts new cells in a worksheet, shifting other cells in the same column down.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void InsertCells(
    CellRange range
)
vb
Sub InsertCells(
    range As CellRange
)

Parameters

NameTypeDescription
rangeCellRange

A CellRange object specifying a cell range where new cells should be inserted.

|

Remarks

To delete cells, use the Worksheet.DeleteCells method (see the How to: Delete a Cell or Range of Cells example).

Another way to insert and delete the cell range is to use the range’s RangeExtensions.Insert and RangeExtensions.Delete extension methods, defined by the RangeExtensions class. These extension methods are accessible as methods of the CellRange object and called by using the instance method syntax.

Example

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

Row.Insert

RowCollection.Insert*

Column.Insert

ColumnCollection.Insert*

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

Worksheet Interface

Worksheet Members

DevExpress.Spreadsheet Namespace