officefileapi-devexpress-dot-spreadsheet-dot-cellrange-dot-exclude-x28-devexpress-dot-spreadsheet-dot-cellrange-x29.md
Excludes the specified cell or cell range from the current range.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
CellRange Exclude(
CellRange other
)
Function Exclude(
other As CellRange
) As CellRange
| Name | Type | Description |
|---|---|---|
| other | CellRange |
A CellRange object that specifies the cell or cell range to be excluded from the source range.
|
| Type | Description |
|---|---|
| CellRange |
A CellRange object that is the resulting contiguous or noncontiguous (union) range of cells.
|
Use the Exclude method to exclude a specific cell or cell range from the cell range that calls this method. Take into account the following special cases.
The following example demonstrates how to use the Exclude method to exclude a specific cell range from the CellRange object.
using DevExpress.Spreadsheet;
using System.Drawing;
// ...
IWorkbook workbook = spreadsheetControl1.Document;
Worksheet worksheet = workbook.Worksheets["Sheet1"];
CellRange sourceRange = worksheet.Range["B2:E7"];
CellRange excludedRange = worksheet.Range["C4:D5"];
// Exclude the cell range "C4:D5" from the range "B2:E7".
CellRange resultantRange = sourceRange.Exclude(excludedRange);
// Fill the resultant cell range with the specified color.
resultantRange.Fill.BackgroundColor = Color.FromArgb(0xFA, 0xDA, 0xDD);
Imports DevExpress.Spreadsheet
Imports System.Drawing
' ...
Private workbook As IWorkbook = spreadsheetControl1.Document
Private worksheet As Worksheet = workbook.Worksheets("Sheet1")
Private sourceRange As CellRange = worksheet.Range("B2:E7")
Private excludedRange As CellRange = worksheet.Range("C4:D5")
' Exclude the cell range "C4:D5" from the range "B2:E7".
Private resultantRange As CellRange = sourceRange.Exclude(excludedRange)
' Fill the resultant cell range with the specified color.
resultantRange.Fill.BackgroundColor = Color.FromArgb(&HFA, &HDA, &HDD)
The result of code execution is shown in the image below.
To combine multiple cell ranges in a worksheet into a single complex range, use the CellRange.Union method.
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Exclude(CellRange) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
// except for rows 1 through 11.
var range = Sheet.GetDataRange().Exclude(Sheet["1:11"]);
if (range != null)
See Also