|
7 | 7 | use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
8 | 8 | use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
9 | 9 | use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
| 10 | +use PhpOffice\PhpSpreadsheet\Worksheet\Validations; |
10 | 11 | use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
11 | 12 |
|
12 | 13 | class Offset
|
@@ -55,19 +56,22 @@ public static function OFFSET(?string $cellAddress = null, mixed $rows = 0, mixe
|
55 | 56 | if (!is_object($cell)) {
|
56 | 57 | return ExcelError::REF();
|
57 | 58 | }
|
| 59 | + $sheet = $cell->getParent()?->getParent(); // worksheet |
| 60 | + if ($sheet !== null) { |
| 61 | + $cellAddress = Validations::definedNameToCoordinate($cellAddress, $sheet); |
| 62 | + } |
58 | 63 |
|
59 | 64 | [$cellAddress, $worksheet] = self::extractWorksheet($cellAddress, $cell);
|
60 | 65 |
|
61 | 66 | $startCell = $endCell = $cellAddress;
|
62 | 67 | if (strpos($cellAddress, ':')) {
|
63 | 68 | [$startCell, $endCell] = explode(':', $cellAddress);
|
64 | 69 | }
|
65 |
| - [$startCellColumn, $startCellRow] = Coordinate::coordinateFromString($startCell); |
66 |
| - [$endCellColumn, $endCellRow] = Coordinate::coordinateFromString($endCell); |
| 70 | + [$startCellColumn, $startCellRow] = Coordinate::indexesFromString($startCell); |
| 71 | + [, $endCellRow, $endCellColumn] = Coordinate::indexesFromString($endCell); |
67 | 72 |
|
68 | 73 | $startCellRow += $rows;
|
69 |
| - $startCellColumn = Coordinate::columnIndexFromString($startCellColumn) - 1; |
70 |
| - $startCellColumn += $columns; |
| 74 | + $startCellColumn += $columns - 1; |
71 | 75 |
|
72 | 76 | if (($startCellRow <= 0) || ($startCellColumn < 0)) {
|
73 | 77 | return ExcelError::REF();
|
|
0 commit comments