Skip to main content
Row

CellRange.GetMinimumCover() Method

Returns the cell range that covers the current range and does not contain the intersecting ranges.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v24.1.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

CellRange GetMinimumCover()

Returns

Type Description
CellRange

A CellRange object that is a contiguous or noncontiguous (union) range that covers the same cells as the current range excluding the intersecting areas.

Remarks

Use the GetMinimumCover method to get a cell range that consists of non-intersecting ranges whose union equals the current range. This can be useful when you need to obtain all cells of a complex range without intersecting areas (e.g., to perform calculations on these cells).

For instance, let’s consider you need to count the number of cells in a multiple-area selection (B2:C4, C4:E7 and E2:F4, in the image below) that contains duplicated cells (C4 and E4).

Spreadsheet_SelectedRange_Complex

To solve this task, call the GetMinimumCover method for a union range of selected areas the Worksheet.Selection property returns. The resulting union range contains the same cells as the selected ranges, but without intersecting areas.

Spreadsheet_Range_GetMinimumCover

The code snippet below demonstrates this approach:

IWorkbook workbook = spreadsheetControl.Document;
Worksheet worksheet = workbook.Worksheets.ActiveWorksheet;

// Get the range that covers the selected cells, 
// but does not contain the intersecting areas.
CellRange selectedCells = worksheet.Selection.GetMinimumCover();

// Count the number of selected cells.
int cellCount = 0;
foreach (CellRange range in selectedCells.Areas)
    cellCount += range.RowCount * range.ColumnCount;
See Also