All docs
V20.2
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
Row

Worksheet.DeleteCells(CellRange, DeleteMode) Method

Deletes cells from the worksheet.

Namespace: DevExpress.Spreadsheet

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

Declaration

void DeleteCells(
    CellRange range,
    DeleteMode mode
)
Sub DeleteCells(
    range As CellRange,
    mode As DeleteMode
)

Parameters

Name Type Description
range CellRange

A CellRange object specifying a cell range to be deleted from the worksheet.

mode DeleteMode

A DeleteMode enumeration member specifying in which direction to shift other cells.

Remarks

Use the DeleteCells method to delete the specified cell range from the worksheet.

You can delete a cell range and shift other cells in the same column up, or shift other cells in the same row to the left. You can also delete entire rows and columns that comprise the specified range of cells. In this case, other rows and columns are automatically shifted up or to the left. For more information on deleting rows and columns, refer to the How to: Delete a Row or Column from a Worksheet example.

To delete only cell content or formatting without removing entire cells from the worksheet, use the Worksheet.ClearContents, Worksheet.ClearFormats, Worksheet.ClearHyperlinks, Worksheet.ClearComments or Worksheet.Clear method (see the How to: Clear Cells of Content, Formatting, Hyperlinks and Comments example).

To insert new cells into the worksheet, call the Worksheet.InsertCells method (see the How to: Insert a Cell or Cell Range example).

Another way to insert, delete and clear the cell range is to use the range's RangeExtensions.Insert, RangeExtensions.Delete and Clear* 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.

Examples

This example demonstrates how to delete cells from a worksheet. To do this, use the Worksheet.DeleteCells method. Pass a cell or cell range that you want to delete, and the DeleteMode.ShiftCellsUp or DeleteMode.ShiftCellsLeft enumeration member to specify how to shift other cells.

using DevExpress.Spreadsheet;
// ...

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

// Delete the C5 cell, shifting other cells in the same row to the left.
worksheet.DeleteCells(worksheet.Cells["C5"], DeleteMode.ShiftCellsLeft);

// Delete the H11:I12 range of cells, shifting other cells in the same column up.
worksheet.DeleteCells(worksheet.Range["H11:I12"], DeleteMode.ShiftCellsUp);
See Also