R1C1 conversion should handle absolute A1 references

This commit is contained in:
Nathan Dench 2021-05-04 14:45:04 +10:00 committed by Mark Baker
parent 72a36a5bb8
commit 76ac008911
2 changed files with 31 additions and 3 deletions

View File

@ -102,14 +102,27 @@ class AddressHelper
?int $currentRowNumber = null,
?int $currentColumnNumber = null
): string {
$validityCheck = preg_match('/^\$?([A-Z]{1,3})\$?(\d{1,7})$/i', $address, $cellReference);
$validityCheck = preg_match('/^(\$?[A-Z]{1,3})(\$?\d{1,7})$/i', $address, $cellReference);
if ($validityCheck === 0) {
throw new Exception('Invalid A1-format Cell Reference');
}
if ($cellReference[1][0] === '$') {
$columnId = Coordinate::columnIndexFromString(substr($cellReference[1], 1));
// Column must be absolute address
$currentColumnNumber = null;
} else {
$columnId = Coordinate::columnIndexFromString($cellReference[1]);
}
if ($cellReference[2][0] === '$') {
$rowId = (int) substr($cellReference[2], 1);
// Row must be absolute address
$currentRowNumber = null;
} else {
$rowId = (int) $cellReference[2];
}
if ($currentRowNumber !== null) {
if ($rowId === $currentRowNumber) {

View File

@ -2,18 +2,33 @@
return [
['R[2]C[2]', 'O18', 16, 13],
['R18C15', '$O$18', 16, 13],
['R[-2]C[2]', 'O14', 16, 13],
['R[-2]C15', '$O14', 16, 13],
['R[2]C[-2]', 'K18', 16, 13],
['R18C[-2]', 'K$18', 16, 13],
['R[-2]C[-2]', 'K14', 16, 13],
['RC[3]', 'P16', 16, 13],
['R16C[3]', 'P$16', 16, 13],
['RC[-3]', 'J16', 16, 13],
['RC10', '$J16', 16, 13],
['R[4]C', 'M20', 16, 13],
['R[4]C13', '$M20', 16, 13],
['R[-4]C', 'M12', 16, 13],
['R12C', 'M$12', 16, 13],
['RC', 'E5', 5, 5],
['R5C5', '$E$5', 5, 5],
['R5C', 'E5', null, 5],
['R5C5', '$E5', null, 5],
['R5C', 'E$5', null, 5],
['RC5', 'E5', 5, null],
['RC5', '$E5', 5, null],
['R5C5', 'E$5', 5, null],
['R5C[2]', 'E5', null, 3],
['R5C5', '$E5', null, 3],
['R5C[2]', 'E$5', null, 3],
['R[2]C5', 'E5', 3, null],
['R5C5', '$E$5', 3, null],
['R5C[-2]', 'E5', null, 7],
['R[-2]C5', 'E5', 7, null],
];