Back to Devexpress

CellRange.GetReferenceA1(ReferenceElement) Method

officefileapi-devexpress-dot-spreadsheet-dot-cellrange-dot-getreferencea1-x28-devexpress-dot-spreadsheet-dot-referenceelement-x29.md

latest6.0 KB
Original Source

CellRange.GetReferenceA1(ReferenceElement) Method

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

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
string GetReferenceA1(
    ReferenceElement options
)
vb
Function GetReferenceA1(
    options As ReferenceElement
) 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.

|

Returns

TypeDescription
String

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

|

Remarks

Use the CellRange.GetReferenceR1C1 method to get cell references in the R1C1 reference style.

Example

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

csharp
using DevExpress.Spreadsheet;
// ...

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

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

// Returns the relative range reference - "B3:D5".
string refRel = range.GetReferenceA1();

// Returns the relative range reference that includes the worksheet name - "Sheet1!B3:D5".
string refSheet = range.GetReferenceA1(ReferenceElement.IncludeSheetName);

// Returns the absolute range reference - "$B$3:$D$5".
string refAbs = range.GetReferenceA1(ReferenceElement.ColumnAbsolute | ReferenceElement.RowAbsolute);

// Returns the mixed range reference (with absolute row and relative column) 
// that includes the worksheet name - "Sheet1!B$3:D$5".
string refMixed = range.GetReferenceA1(ReferenceElement.RowAbsolute | ReferenceElement.IncludeSheetName);
vb
Imports DevExpress.Spreadsheet
' ...

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

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

' Returns the relative range reference - "B3:D5".
Dim refRel As String = range.GetReferenceA1()

' Returns the relative range reference that includes the worksheet name - "Sheet1!B3:D5".
Dim refSheet As String = range.GetReferenceA1(ReferenceElement.IncludeSheetName)

' Returns the absolute range reference - "$B$3:$D$5".
Dim refAbs As String = range.GetReferenceA1(ReferenceElement.ColumnAbsolute Or ReferenceElement.RowAbsolute)

' Returns the mixed range reference (with absolute row and relative column) 
' that includes the worksheet name - "Sheet1!B$3:D$5".
Dim refMixed As String = range.GetReferenceA1(ReferenceElement.RowAbsolute Or ReferenceElement.IncludeSheetName)

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetReferenceA1(ReferenceElement) 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-use-custom-cell-editors/CS/DevAVInvoicing/Form1.cs#L135

csharp
if (e.Action == CellValueChangedAction.UndoRedo || e.OldValue == e.Cell.Value ||
    e.Cell.GetReferenceA1(ReferenceElement.IncludeSheetName) != "Invoice!B10")
    return;

winforms-spreadsheet-use-custom-cell-editors/VB/DevAVInvoicing/Form1.vb#L124

vb
Private Sub spreadsheetControl1_CellValueChanged(ByVal sender As Object, ByVal e As SpreadsheetCellEventArgs)
    If e.Action = CellValueChangedAction.UndoRedo OrElse e.OldValue Is e.Cell.Value OrElse Not Equals(e.Cell.GetReferenceA1(ReferenceElement.IncludeSheetName), "Invoice!B10") Then Return
    Dim invoice As Worksheet = e.Worksheet

See Also

GetReferenceR1C1

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