How to: Delete a Cell or Range of Cells
- 2 minutes to read
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; // 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);
To delete cell content or formatting without removing an entire cell from the worksheet, use the Clear* methods of the Worksheet object (see the How to: Clear Cells of Content, Formatting, Hyperlinks and Comments example).