Back to Devexpress

IRangeProvider.Union(CellRange[]) Method

officefileapi-devexpress-dot-spreadsheet-dot-irangeprovider-dot-union-x28-devexpress-dot-spreadsheet-dot-cellrange-x29.md

latest8.3 KB
Original Source

IRangeProvider.Union(CellRange[]) Method

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

Declaration

csharp
CellRange Union(
    params CellRange[] ranges
)
vb
Function Union(
    ParamArray ranges As CellRange()
) As CellRange

Parameters

NameTypeDescription
rangesCellRange[]

An array of CellRange objects.

|

Returns

TypeDescription
CellRange

A CellRange composed of multiple ranges.

|

Remarks

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.

Ranges which comprise a complex range can be accessed using the CellRange.Areas property.

View Example

csharp
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;
vb
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

The following code snippets (auto-collected from DevExpress Examples) contain references to the Union(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.

winforms-spreadsheet-apply-conditional-formatting-to-a-range-of-cells/CS/SpreadsheetControl/SpreadsheetActions/ConditionalFormatting.cs#L409

csharp
// Create a union range to which the rule will be applied.
CellRange complexRange = worksheet.Range.Union(worksheet["G3:G6"], worksheet["G9:G12"]);

winforms-spreadsheetcontrol-api-part-3/CS/SpreadsheetControl_API_Part03/CodeExamples/DataValidationActions.cs#L78

csharp
// Create a union range.
CellRange range = worksheet.Range.Union(worksheet["F4:F5"], worksheet["F6:F11"]);
// Restrict data entry to a number within limits.

wpf-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/DataValidationActions.cs#L90

csharp
// Create a union range.
CellRange range = worksheet.Range.Union(worksheet["F4:F5"], worksheet["F6:F11"]);
// Restrict data entry to a number within limits.

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/DataValidationActions.cs#L104

csharp
// Create a union range.
CellRange range = worksheet.Range.Union(worksheet["F4:F5"], worksheet["F6:F11"]);

winforms-spreadsheet-apply-conditional-formatting-to-a-range-of-cells/VB/SpreadsheetControl/SpreadsheetActions/ConditionalFormatting.vb#L358

vb
' Create a union range to which the rule will be applied.
Dim complexRange As CellRange = worksheet.Range.Union(worksheet("G3:G6"), worksheet("G9:G12"))

winforms-spreadsheetcontrol-api-part-3/VB/SpreadsheetControl_API_Part03/CodeExamples/DataValidationActions.vb#L65

vb
' Create a union range.
Dim range As DevExpress.Spreadsheet.CellRange = worksheet.Range.Union(worksheet("F4:F5"), worksheet("F6:F11"))
' Restrict data entry to a number within limits.

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/DataValidationActions.vb#L100

vb
' Create a union range.
Dim range As CellRange = worksheet.Range.Union(worksheet("F4:F5"), worksheet("F6:F11"))

See Also

IRangeProvider Interface

IRangeProvider Members

DevExpress.Spreadsheet Namespace