Back to Devexpress

IRangeProvider Interface

officefileapi-devexpress-dot-spreadsheet-5ca4a9eb.md

latest8.2 KB
Original Source

IRangeProvider Interface

Provides properties and methods to get cell ranges.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public interface IRangeProvider
vb
Public Interface IRangeProvider

The following members return IRangeProvider objects:

Remarks

Use the Worksheet.Range, IWorkbook.Range or Workbook.Range properties to get the IRangeProvider object. This object’s IRangeProvider.Item property allows you to get a cell range by its reference in the A1 reference style. To access a cell range by its R1C1 reference, use the IRangeProvider.Parse method. The IRangeProvider.FromLTRB method returns a cell range by the indexes of the bounding rows and columns.

Example

This example demonstrates how to access ranges of cells in a worksheet. There are several ways to accomplish this.

View Example

csharp
// A range that includes cells from the top left cell (A1) to the bottom right cell (B5).
CellRange rangeA1B5 = worksheet["A1:B5"];

// A rectangular range that includes cells from the top left cell (C5) to the bottom right cell (E7).
CellRange rangeC5E7 = worksheet["C5:E7"];

// The C4:E7 cell range located in the "Sheet3" worksheet.
CellRange rangeSheet3C4E7 = workbook.Range["Sheet3!C4:E7"];

// A range that contains a single cell (E7).
CellRange rangeE7 = worksheet["E7"];

// A range that includes the entire column A.
CellRange rangeColumnA = worksheet["A:A"];

// A range that includes the entire row 5.
CellRange rangeRow5 = worksheet["5:5"];

// A minimal rectangular range that includes all listed cells: C6, D9 and E7.
CellRange rangeC6D9E7 = worksheet.Range.Parse("C6:D9:E7");

// A rectangular range whose left column index is 0, top row index is 0, 
// right column index is 3 and bottom row index is 2. This is the A1:D3 cell range.
CellRange rangeA1D3 = worksheet.Range.FromLTRB(0, 0, 3, 2);

// A range that includes the intersection of two ranges: C5:E10 and E9:G13. 
// This is the E9:E10 cell range.
CellRange rangeE9E10 = worksheet["C5:E10 E9:G13"];

// Create a defined name for the D20:G23 cell range.
worksheet.DefinedNames.Add("MyNamedRange", "Sheet1!$D$20:$G$23");
// Access a range by its defined name.
CellRange rangeD20G23 = worksheet["MyNamedRange"];
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
' A range that includes cells from the top left cell (A1) to the bottom right cell (B5).
Dim rangeA1B5 As CellRange = worksheet("A1:B5")

' A rectangular range that includes cells from the top left cell (C5) to the bottom right cell (E7).
Dim rangeC5E7 As CellRange = worksheet("C5:E7")

' The C4:E7 cell range located in the "Sheet3" worksheet.
Dim rangeSheet3C4E7 As CellRange = workbook.Range("Sheet3!C4:E7")

' A range that contains a single cell (E7).
Dim rangeE7 As CellRange = worksheet("E7")

' A range that includes the entire column A.
Dim rangeColumnA As CellRange = worksheet("A:A")

' A range that includes the entire row 5.
Dim rangeRow5 As CellRange = worksheet("5:5")

' A minimal rectangular range that includes all listed cells: C6, D9 and E7.
Dim rangeC6D9E7 As CellRange = worksheet.Range.Parse("C6:D9:E7")

' A rectangular range whose left column index is 0, top row index is 0, 
' right column index is 3 and bottom row index is 2. This is the A1:D3 cell range.
Dim rangeA1D3 As CellRange = worksheet.Range.FromLTRB(0, 0, 3, 2)

' A range that includes the intersection of two ranges: C5:E10 and E9:G13. 
' This is the E9:E10 cell range.
Dim rangeE9E10 As CellRange = worksheet("C5:E10 E9:G13")

' Create a defined name for the D20:G23 cell range.
worksheet.DefinedNames.Add("MyNamedRange", "Sheet1!$D$20:$G$23")
' Access a range by its defined name.
Dim rangeD20G23 As CellRange = worksheet("MyNamedRange")
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

IRangeProvider Members

How to: Access a Cell in a Worksheet

How to: Access a Row or Column

DevExpress.Spreadsheet Namespace