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 getAddress method 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 getAddress method.
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.
Java |
Copy Code |
---|---|
// Create a new workbook Workbook workbook = new Workbook(); IRange mc = workbook.getWorksheets().get("Sheet1").getCells().get(0, 0); // Get absolute address in A1 notation System.out.println(mc.getAddress()); // Get row's relative and column's absolute address in A1 notation System.out.println(mc.getAddress(false, true)); // Get absolute address in R1C1 notation System.out.println(mc.getAddress(true, true, ReferenceStyle.R1C1)); // Get relative address in R1C1 notation System.out.println(mc.getAddress(false, false, ReferenceStyle.R1C1, workbook.getWorksheets().get(0).getCells().get(2, 2))); |