Get Address of Cell Range | Document Solutions for Excel, .NET Edition | Document Solutions
Features / Worksheet / Range Operations / Get Address of Cell Range
Get Address of Cell Range

In DsExcel, the address of cells or their ranges can be retrieved in A1 or R1C1 notation (both absolute and relative references). The read-only Address property of IRange interface can be used to get the range reference in absolute A1 format. However, you can use the GetAddress method of IRange interface to define the reference notation and absolute and relative references. It takes 4 optional parameters which when omitted, return the same value as Address property.

The below table elaborates how to use DsExcel API members to retrieve the address of cell[0,0] in different notations and references. 

Cell Reference Notation Absolute Reference Relative Reference
A1

Address property

Output: $A$1

GetAddress method (set rowAbsolute and columnAbsolute parameters to False)

Output: A1

 

R1C1

GetAddress method (set referenceStyle parameter to R1C1)

Output: R1C1

 

GetAddress method (set referenceStyle parameter to R1C1, rowAbsolute and columnAbsolute parameters to False)

Output: RC

 

Refer to the below example code to retrieve the address of a cell in different notations and references.

C#
Copy Code
//create a new workbook
var workbook = new GrapeCity.Documents.Excel.Workbook();
var mc = workbook.Worksheets["Sheet1"].Cells[0,0];

//get absolute address in A1 notation
Console.WriteLine(mc.Address);

//get row's relative and column's absolute address in A1 notation
Console.WriteLine(mc.GetAddress(rowAbsolute: false));

//get absolute address in R1C1 notation
Console.WriteLine(mc.GetAddress(referenceStyle: ReferenceStyle.R1C1));

//get relative address in R1C1 notation
Console.WriteLine(mc.GetAddress(referenceStyle: ReferenceStyle.R1C1,
  rowAbsolute: false,
  columnAbsolute: false,
  relativeTo: workbook.Worksheets[0].Cells[2, 2]));