officefileapi-devexpress-dot-spreadsheet-dot-cellrange-dot-union-x28-devexpress-dot-spreadsheet-dot-cellrange-x29.md
Creates a complex range that is the union of multiple ranges.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
CellRange Union(
CellRange other
)
Function Union(
other As CellRange
) As CellRange
| Name | Type | Description |
|---|---|---|
| other | CellRange |
A CellRange object.
|
| Type | Description |
|---|---|
| CellRange |
A CellRange composed of multiple ranges.
|
A complex (union) range can be also created by multiple selection in a worksheet. A complex range can be used in the same manner as a simple range. The CellRange.Areas property provides access to the ranges to which a complex range is comprised.
This example demonstrates how to create a complex (union) range. There are several ways to accomplish this.
CellRange.Union method to combine a single range with another range.Ranges which comprise a complex range can be accessed using the CellRange.Areas property.
CellRange rangeA1D4 = worksheet["A1:D4"];
CellRange rangeD5E7 = worksheet["D5:E7"];
CellRange rangeRow11 = worksheet["11:11"];
CellRange rangeF7 = worksheet["F7"];
// Create a complex range using the Range.Union method.
CellRange complexRange1 = worksheet["A7:A9"].Union(rangeD5E7);
// Create a complex range using the IRangeProvider.Union method.
CellRange complexRange2 = worksheet.Range.Union(new CellRange[] { rangeRow11, rangeA1D4, rangeF7 });
// Fill the ranges with different colors.
complexRange1.FillColor = myColor1;
complexRange2.FillColor = myColor2;
// Use the Areas property to get access to a component of a complex range.
complexRange2.Areas[2].FillColor = Color.Beige;
Dim rangeA1D4 As CellRange = worksheet("A1:D4")
Dim rangeD5E7 As CellRange = worksheet("D5:E7")
Dim rangeRow11 As CellRange = worksheet("11:11")
Dim rangeF7 As CellRange = worksheet("F7")
' Create a complex range using the Range.Union method.
Dim complexRange1 As CellRange = worksheet("A7:A9").Union(rangeD5E7)
' Create a complex range using the IRangeProvider.Union method.
Dim complexRange2 As CellRange = worksheet.Range.Union(New CellRange() { rangeRow11, rangeA1D4, rangeF7 })
' Fill the ranges with different colors.
complexRange1.FillColor = myColor1
complexRange2.FillColor = myColor2
' Use the Areas property to get access to a component of a complex range.
complexRange2.Areas(2).FillColor = Color.Beige
See Also