Back to Devexpress

CellRange.GetReferenceR1C1(ReferenceElement, Cell) Method

officefileapi-devexpress-dot-spreadsheet-dot-cellrange-dot-getreferencer1c1-x28-devexpress-dot-spreadsheet-dot-referenceelement-devexpress-dot-spreadsheet-dot-cell-x29.md

latest5.4 KB
Original Source

CellRange.GetReferenceR1C1(ReferenceElement, Cell) Method

Gets the cell or cell range reference in the R1C1 reference style.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
string GetReferenceR1C1(
    ReferenceElement options,
    Cell baseCell
)
vb
Function GetReferenceR1C1(
    options As ReferenceElement,
    baseCell As Cell
) As String

Parameters

NameTypeDescription
optionsReferenceElement

A ReferenceElement enumeration values that specify whether to return the relative, absolute or mixed cell reference, and whether to precede it with the worksheet name.

| | baseCell | Cell |

A Cell object that specifies the base cell relative to which the relative elements of the cell reference (row or column, or both) should be obtained, if the cell reference is relative or mixed. If the cell reference is absolute, pass null ( Nothing in Visual Basic).

|

Returns

TypeDescription
String

A String value that specifies the R1C1-style reference to a cell or range of cells.

|

Remarks

Use the CellRange.GetReferenceA1 method to get cell references in the A1 reference style.

Example

This example demonstrates how to get R1C1-style references (relative, absolute and mixed) to a range of cells.

csharp
using DevExpress.Spreadsheet;
// ...

IWorkbook workbook = spreadsheetControl1.Document;
Worksheet worksheet = workbook.Worksheets["Sheet1"];

CellRange range = worksheet.Range["B3:D5"];

// Returns the range reference relative to cell E7 - "R[-4]C[-3]:R[-2]C[-1]".
string refRel = range.GetReferenceR1C1(worksheet.Cells["E7"]);

// Returns the range reference relative to cell A4, including the worksheet name - 
// "Sheet1!R[-1]C[1]:R[1]C[3]".
string refSheet = range.GetReferenceR1C1(ReferenceElement.IncludeSheetName, worksheet.Cells["A4"]);

// Returns the mixed range reference (with absolute row reference and column reference relative to cell B2),
// including the worksheet name - "Sheet1!R3C[-1]:R5C[1]".
string refMixed = range.GetReferenceR1C1(ReferenceElement.RowAbsolute | ReferenceElement.IncludeSheetName,
                                        worksheet.Cells["B2"]);

// Returns the absolute range reference - "R3C2:R5C4".
string refAbs = range.GetReferenceR1C1(ReferenceElement.RowAbsolute | ReferenceElement.ColumnAbsolute, null);
vb
Imports DevExpress.Spreadsheet
' ...

Dim workbook As IWorkbook = spreadsheetControl1.Document
Dim worksheet As Worksheet = workbook.Worksheets("Sheet1")

Dim range As CellRange = worksheet.Range("B3:D5")

' Returns the range reference relative to cell E7 - "R[-4]C[-3]:R[-2]C[-1]".
Dim refRel As String = range.GetReferenceR1C1(worksheet.Cells("E7"))

' Returns the range reference relative to cell A4, including the worksheet name - 
' "Sheet1!R[-1]C[1]:R[1]C[3]".
Dim refSheet As String = range.GetReferenceR1C1(ReferenceElement.IncludeSheetName, worksheet.Cells("A4"))

' Returns the mixed range reference (with absolute row reference and column reference relative to cell B2),
' including the worksheet name - "Sheet1!R3C[-1]:R5C[1]".
Dim refMixed As String = range.GetReferenceR1C1(ReferenceElement.RowAbsolute Or ReferenceElement.IncludeSheetName, _
                                                worksheet.Cells("B2"))

' Returns the absolute range reference - "R3C2:R5C4".
Dim refAbs As String = range.GetReferenceR1C1(ReferenceElement.RowAbsolute Or ReferenceElement.ColumnAbsolute, Nothing)

See Also

GetReferenceA1

How to: Access a Cell in a Worksheet

How to: Access a Range of Cells

How to: Use Cell and Worksheet References in Formulas

CellRange Interface

CellRange Members

DevExpress.Spreadsheet Namespace