Back to Devexpress

CellRange.GetReferenceA1() Method

officefileapi-devexpress-dot-spreadsheet-dot-cellrange-dot-getreferencea1-3135f0be.md

latest9.1 KB
Original Source

CellRange.GetReferenceA1() Method

Gets the relative 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()
vb
Function GetReferenceA1 As String

Returns

TypeDescription
String

A String value that specifies the A1-style relative 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 snippets (auto-collected from DevExpress Examples) contain references to the GetReferenceA1() 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-control-create-a-data-entry-form/CS/DataEntryFormSample/SpreadsheetBindingManager.cs#L229

csharp
{
    string reference = e.Cell.GetReferenceA1();
    string propertyName = cellBindings.SingleOrDefault(p => p.Value == reference).Key;

wpf-spreadsheet-control-create-a-data-entry-form/CS/WpfDataEntryFormSample/SpreadsheetBindingManager.cs#L217

csharp
{
    string reference = e.Cell.GetReferenceA1();
    string propertyName = cellBindings.SingleOrDefault(p => p.Value == reference).Key;

wpf-spreadsheet-bind-spreadsheet-to-ms-sql-server-database/CS/WpfSpreadsheet_BindToDataSource/MainWindow.xaml.cs#L51

csharp
Worksheet sheet = spreadsheetControl.ActiveWorksheet;
string cellReference = cell.GetReferenceA1();
// If the "Save" cell is clicked in the data entry form,

winforms-spreadsheet-bind-to-ms-sql-server-database/CS/SuppliersExample/Form1.cs#L42

csharp
Worksheet sheet = spreadsheetControl1.ActiveWorksheet;
string cellReference = cell.GetReferenceA1();
// If the "Save" cell is clicked in the data entry form,

how-to-export-cell-range-to-a-datatable/CS/ExportToDataTableExample/Form1.cs#L181

csharp
{
    MessageBox.Show("Error in cell " + e.Cell.GetReferenceA1());
    e.DataTableValue = null;

winforms-spreadsheet-control-create-a-data-entry-form/VB/DataEntryFormSample/SpreadsheetBindingManager.vb#L198

vb
If e.SheetName = SheetName Then
    Dim reference As String = e.Cell.GetReferenceA1()
    Dim propertyName As String = cellBindings.SingleOrDefault(Function(p) p.Value = reference).Key

wpf-spreadsheet-control-create-a-data-entry-form/VB/WpfDataEntryFormSample/SpreadsheetBindingManager.vb#L195

vb
If e.SheetName = SheetName Then
    Dim reference As String = e.Cell.GetReferenceA1()
    Dim propertyName As String = cellBindings.SingleOrDefault(Function(p) p.Value = reference).Key

wpf-spreadsheet-bind-spreadsheet-to-ms-sql-server-database/VB/WpfSpreadsheet_BindToDataSource/MainWindow.xaml.vb#L50

vb
Dim sheet As Worksheet = Me.spreadsheetControl.ActiveWorksheet
Dim cellReference As String = cell.GetReferenceA1()
' If the "Save" cell is clicked in the data entry form,

spreadsheet-document-api-export-worksheet-range-to-datatable/VB/ExportToDataTableWorkbookExample/Form1.vb#L50

vb
Private Sub exporter_CellValueConversionError(ByVal sender As Object, ByVal e As CellValueConversionErrorEventArgs)
    MessageBox.Show("Error in cell " & e.Cell.GetReferenceA1())
    e.DataTableValue = Nothing

winforms-spreadsheet-bind-to-ms-sql-server-database/VB/SuppliersExample/Form1.vb#L44

vb
Dim sheet As Worksheet = spreadsheetControl1.ActiveWorksheet
Dim cellReference As String = cell.GetReferenceA1()
' If the "Save" cell is clicked in the data entry form,

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