Skip to main content
A newer version of this page is available.
All docs
V18.2
Row

Worksheet.DeleteCells(Range) Method

Deletes cells from a worksheet, shifting other cells in the same row to the left.

Namespace: DevExpress.Spreadsheet

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

Declaration

void DeleteCells(
    Range range
)

Parameters

Name Type Description
range Range

A Range object specifying a cell range to be deleted.

Remarks

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 Range object and called by using the instance method syntax.

Example

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