Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove complexity from AddressHelper::convertToR1C1
  • Loading branch information
ndench committed May 5, 2021
commit c2fa05994f2c6ab7613192dd919c5f3919bf7bf9
14 changes: 5 additions & 9 deletions src/PhpSpreadsheet/Cell/AddressHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,22 @@ public static function convertToR1C1(
?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));
$columnId = Coordinate::columnIndexFromString($cellReference[2]);
if ($cellReference[1] === '$') {
// Column must be absolute address
$currentColumnNumber = null;
} else {
$columnId = Coordinate::columnIndexFromString($cellReference[1]);
}

if ($cellReference[2][0] === '$') {
$rowId = (int) substr($cellReference[2], 1);
$rowId = (int) $cellReference[4];
if ($cellReference[3] === '$') {
// Row must be absolute address
$currentRowNumber = null;
} else {
$rowId = (int) $cellReference[2];
}

if ($currentRowNumber !== null) {
Expand Down