Back to Devexpress

ReferenceElement Enum

officefileapi-devexpress-dot-spreadsheet-64ff9f97.md

latest3.9 KB
Original Source

ReferenceElement Enum

Contains values to specify the type of a cell reference to be obtained.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
[Flags]
public enum ReferenceElement
vb
<Flags>
Public Enum ReferenceElement

Members

NameDescription
RowAbsolute

The cell reference has the absolute row reference.

| | ColumnAbsolute |

The cell reference has the absolute column reference.

| | IncludeSheetName |

The cell reference includes the worksheet name.

|

Remarks

Use this enumeration’s values in the CellRange.GetReferenceA1 and CellRange.GetReferenceR1C1 methods to specify the type of the cell reference to be returned (relative, absolute or mixed) and whether it should include the worksheet name.

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

Cell Referencing

DevExpress.Spreadsheet Namespace