Skip to content

Commit e0150fd

Browse files
committed
Extract coordinate methods to Coordinate class
1 parent 1cec980 commit e0150fd

36 files changed

+859
-845
lines changed

samples/Basic/40_Duplicate_style.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use PhpOffice\PhpSpreadsheet\Cell\Cell;
3+
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
44
use PhpOffice\PhpSpreadsheet\Spreadsheet;
55
use PhpOffice\PhpSpreadsheet\Style\Style;
66

@@ -24,7 +24,7 @@
2424
for ($row = 0; $row < 100; ++$row) {
2525
$str = ($row + $col);
2626
$style = $styles[$row % 10];
27-
$coord = Cell::stringFromColumnIndex($col) . ($row + 1);
27+
$coord = Coordinate::stringFromColumnIndex($col) . ($row + 1);
2828
$worksheet->setCellValue($coord, $str);
2929
$worksheet->duplicateStyle($style, $coord);
3030
}

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PhpOffice\PhpSpreadsheet\Calculation\Engine\Logger;
77
use PhpOffice\PhpSpreadsheet\Calculation\Token\Stack;
88
use PhpOffice\PhpSpreadsheet\Cell\Cell;
9+
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
910
use PhpOffice\PhpSpreadsheet\NamedRange;
1011
use PhpOffice\PhpSpreadsheet\Shared;
1112
use PhpOffice\PhpSpreadsheet\Spreadsheet;
@@ -3491,11 +3492,11 @@ private function processTokenStack($tokens, $cellID = null, Cell $pCell = null)
34913492
$oData = array_merge(explode(':', $operand1Data['reference']), explode(':', $operand2Data['reference']));
34923493
$oCol = $oRow = [];
34933494
foreach ($oData as $oDatum) {
3494-
$oCR = Cell::coordinateFromString($oDatum);
3495-
$oCol[] = Cell::columnIndexFromString($oCR[0]) - 1;
3495+
$oCR = Coordinate::coordinateFromString($oDatum);
3496+
$oCol[] = Coordinate::columnIndexFromString($oCR[0]) - 1;
34963497
$oRow[] = $oCR[1];
34973498
}
3498-
$cellRef = Cell::stringFromColumnIndex(min($oCol)) . min($oRow) . ':' . Cell::stringFromColumnIndex(max($oCol)) . max($oRow);
3499+
$cellRef = Coordinate::stringFromColumnIndex(min($oCol)) . min($oRow) . ':' . Coordinate::stringFromColumnIndex(max($oCol)) . max($oRow);
34993500
if ($pCellParent !== null) {
35003501
$cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($sheet1), false);
35013502
} else {
@@ -3564,11 +3565,11 @@ private function processTokenStack($tokens, $cellID = null, Cell $pCell = null)
35643565
foreach (array_keys($rowIntersect) as $row) {
35653566
$oRow[] = $row;
35663567
foreach ($rowIntersect[$row] as $col => $data) {
3567-
$oCol[] = Cell::columnIndexFromString($col) - 1;
3568+
$oCol[] = Coordinate::columnIndexFromString($col) - 1;
35683569
$cellIntersect[$row] = array_intersect_key($operand1[$row], $operand2[$row]);
35693570
}
35703571
}
3571-
$cellRef = Cell::stringFromColumnIndex(min($oCol)) . min($oRow) . ':' . Cell::stringFromColumnIndex(max($oCol)) . max($oRow);
3572+
$cellRef = Coordinate::stringFromColumnIndex(min($oCol)) . min($oRow) . ':' . Coordinate::stringFromColumnIndex(max($oCol)) . max($oRow);
35723573
$this->debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($cellIntersect));
35733574
$stack->push('Value', $cellIntersect, $cellRef);
35743575

@@ -4103,7 +4104,7 @@ public function extractCellRange(&$pRange = 'A1', Worksheet $pSheet = null, $res
41034104
}
41044105

41054106
// Extract range
4106-
$aReferences = Cell::extractAllCellReferencesInRange($pRange);
4107+
$aReferences = Coordinate::extractAllCellReferencesInRange($pRange);
41074108
$pRange = $pSheetName . '!' . $pRange;
41084109
if (!isset($aReferences[1])) {
41094110
// Single cell in range
@@ -4158,7 +4159,7 @@ public function extractNamedRange(&$pRange = 'A1', Worksheet $pSheet = null, $re
41584159
if ($namedRange !== null) {
41594160
$pSheet = $namedRange->getWorksheet();
41604161
$pRange = $namedRange->getRange();
4161-
$splitRange = Cell::splitRange($pRange);
4162+
$splitRange = Coordinate::splitRange($pRange);
41624163
// Convert row and column references
41634164
if (ctype_alpha($splitRange[0][0])) {
41644165
$pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow();
@@ -4170,10 +4171,10 @@ public function extractNamedRange(&$pRange = 'A1', Worksheet $pSheet = null, $re
41704171
}
41714172

41724173
// Extract range
4173-
$aReferences = Cell::extractAllCellReferencesInRange($pRange);
4174+
$aReferences = Coordinate::extractAllCellReferencesInRange($pRange);
41744175
if (!isset($aReferences[1])) {
41754176
// Single cell (or single column or row) in range
4176-
list($currentCol, $currentRow) = Cell::coordinateFromString($aReferences[0]);
4177+
list($currentCol, $currentRow) = Coordinate::coordinateFromString($aReferences[0]);
41774178
if ($pSheet->cellExists($aReferences[0])) {
41784179
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
41794180
} else {
@@ -4183,7 +4184,7 @@ public function extractNamedRange(&$pRange = 'A1', Worksheet $pSheet = null, $re
41834184
// Extract cell data for all cells in the range
41844185
foreach ($aReferences as $reference) {
41854186
// Extract range
4186-
list($currentCol, $currentRow) = Cell::coordinateFromString($reference);
4187+
list($currentCol, $currentRow) = Coordinate::coordinateFromString($reference);
41874188
if ($pSheet->cellExists($reference)) {
41884189
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
41894190
} else {

src/PhpSpreadsheet/Calculation/LookupRef.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PhpOffice\PhpSpreadsheet\Calculation;
44

55
use PhpOffice\PhpSpreadsheet\Cell\Cell;
6+
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
67

78
class LookupRef
89
{
@@ -52,7 +53,7 @@ public static function cellAddress($row, $column, $relativity = 1, $referenceSty
5253
}
5354
if ((!is_bool($referenceStyle)) || $referenceStyle) {
5455
$rowRelative = $columnRelative = '$';
55-
$column = Cell::stringFromColumnIndex($column - 1);
56+
$column = Coordinate::stringFromColumnIndex($column - 1);
5657
if (($relativity == 2) || ($relativity == 4)) {
5758
$columnRelative = '';
5859
}
@@ -98,7 +99,7 @@ public static function COLUMN($cellAddress = null)
9899
foreach ($cellAddress as $columnKey => $value) {
99100
$columnKey = preg_replace('/[^a-z]/i', '', $columnKey);
100101

101-
return (int) Cell::columnIndexFromString($columnKey);
102+
return (int) Coordinate::columnIndexFromString($columnKey);
102103
}
103104
} else {
104105
if (strpos($cellAddress, '!') !== false) {
@@ -110,14 +111,14 @@ public static function COLUMN($cellAddress = null)
110111
$endAddress = preg_replace('/[^a-z]/i', '', $endAddress);
111112
$returnValue = [];
112113
do {
113-
$returnValue[] = (int) Cell::columnIndexFromString($startAddress);
114+
$returnValue[] = (int) Coordinate::columnIndexFromString($startAddress);
114115
} while ($startAddress++ != $endAddress);
115116

116117
return $returnValue;
117118
}
118119
$cellAddress = preg_replace('/[^a-z]/i', '', $cellAddress);
119120

120-
return (int) Cell::columnIndexFromString($cellAddress);
121+
return (int) Coordinate::columnIndexFromString($cellAddress);
121122
}
122123
}
123124

@@ -382,23 +383,23 @@ public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $hei
382383
} else {
383384
$startCell = $endCell = $cellAddress;
384385
}
385-
list($startCellColumn, $startCellRow) = Cell::coordinateFromString($startCell);
386-
list($endCellColumn, $endCellRow) = Cell::coordinateFromString($endCell);
386+
list($startCellColumn, $startCellRow) = Coordinate::coordinateFromString($startCell);
387+
list($endCellColumn, $endCellRow) = Coordinate::coordinateFromString($endCell);
387388

388389
$startCellRow += $rows;
389-
$startCellColumn = Cell::columnIndexFromString($startCellColumn) - 1;
390+
$startCellColumn = Coordinate::columnIndexFromString($startCellColumn) - 1;
390391
$startCellColumn += $columns;
391392

392393
if (($startCellRow <= 0) || ($startCellColumn < 0)) {
393394
return Functions::REF();
394395
}
395-
$endCellColumn = Cell::columnIndexFromString($endCellColumn) - 1;
396+
$endCellColumn = Coordinate::columnIndexFromString($endCellColumn) - 1;
396397
if (($width != null) && (!is_object($width))) {
397398
$endCellColumn = $startCellColumn + $width - 1;
398399
} else {
399400
$endCellColumn += $columns;
400401
}
401-
$startCellColumn = Cell::stringFromColumnIndex($startCellColumn);
402+
$startCellColumn = Coordinate::stringFromColumnIndex($startCellColumn);
402403

403404
if (($height != null) && (!is_object($height))) {
404405
$endCellRow = $startCellRow + $height - 1;
@@ -409,7 +410,7 @@ public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $hei
409410
if (($endCellRow <= 0) || ($endCellColumn < 0)) {
410411
return Functions::REF();
411412
}
412-
$endCellColumn = Cell::stringFromColumnIndex($endCellColumn);
413+
$endCellColumn = Coordinate::stringFromColumnIndex($endCellColumn);
413414

414415
$cellAddress = $startCellColumn . $startCellRow;
415416
if (($startCellColumn != $endCellColumn) || ($startCellRow != $endCellRow)) {

0 commit comments

Comments
 (0)