ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Cell\Coordinate Class Reference

Helper class to manipulate cell coordinates. More...

+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Cell\Coordinate:

Static Public Member Functions

static coordinateFromString ($pCoordinateString)
 Coordinate from string. More...
 
static indexesFromString (string $coordinates)
 Get indexes from a string coordinates. More...
 
static coordinateIsRange ($coord)
 Checks if a coordinate represents a range of cells. More...
 
static absoluteReference ($pCoordinateString)
 Make string row, column or cell coordinate absolute. More...
 
static absoluteCoordinate ($pCoordinateString)
 Make string coordinate absolute. More...
 
static splitRange ($pRange)
 Split range into coordinate strings. More...
 
static buildRange (array $pRange)
 Build range from coordinate strings. More...
 
static rangeBoundaries ($pRange)
 Calculate range boundaries. More...
 
static rangeDimension ($pRange)
 Calculate range dimension. More...
 
static getRangeBoundaries ($pRange)
 Calculate range boundaries. More...
 
static columnIndexFromString ($pString)
 Column index from string. More...
 
static stringFromColumnIndex ($columnIndex)
 String from column index. More...
 
static extractAllCellReferencesInRange ($cellRange)
 Extract all cell references in range, which may be comprised of multiple cell ranges. More...
 
static mergeRangesInCollection (array $pCoordCollection)
 Convert an associative array of single cell coordinates to values to an associative array of cell ranges to values. More...
 

Data Fields

const A1_COORDINATE_REGEX = '/^(?<absolute_col>\$?)(?<col_ref>[A-Z]{1,3})(?<absolute_row>\$?)(?<row_ref>\d{1,7})$/i'
 
const DEFAULT_RANGE = 'A1:A1'
 

Static Private Member Functions

static processRangeSetOperators (array $operators, array $cells)
 
static sortCellReferenceArray (array $cellList)
 
static getReferencesForCellBlock ($cellBlock)
 Get all cell references for an individual cell block. More...
 
static getCellBlocksFromRangeString ($rangeString)
 Get the individual cell blocks from a range string, removing any $ characters. More...
 
static validateRange ($cellBlock, $startColumnIndex, $endColumnIndex, $currentRow, $endRow)
 Check that the given range is valid, i.e. More...
 

Detailed Description

Helper class to manipulate cell coordinates.

Columns indexes and rows are always based on 1, not on 0. This match the behavior that Excel users are used to, and also match the Excel functions COLUMN() and ROW().

Definition at line 14 of file Coordinate.php.

Member Function Documentation

◆ absoluteCoordinate()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::absoluteCoordinate (   $pCoordinateString)
static

Make string coordinate absolute.

Parameters
string$pCoordinateStringe.g. 'A1'
Returns
string Absolute coordinate e.g. '$A$1'

Definition at line 111 of file Coordinate.php.

References $row, and PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\extractSheetTitle().

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xlsx\DefinedNames\writeNamedRangeForAutofilter().

112  {
113  if (self::coordinateIsRange($pCoordinateString)) {
114  throw new Exception('Cell coordinate string can not be a range of cells');
115  }
116 
117  // Split out any worksheet name from the coordinate
118  [$worksheet, $pCoordinateString] = Worksheet::extractSheetTitle($pCoordinateString, true);
119  if ($worksheet > '') {
120  $worksheet .= '!';
121  }
122 
123  // Create absolute coordinate
124  [$column, $row] = self::coordinateFromString($pCoordinateString);
125  $column = ltrim($column, '$');
126  $row = ltrim($row, '$');
127 
128  return $worksheet . '$' . $column . '$' . $row;
129  }
static extractSheetTitle($pRange, $returnRange=false)
Extract worksheet title from range.
Definition: Worksheet.php:2719
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ absoluteReference()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::absoluteReference (   $pCoordinateString)
static

Make string row, column or cell coordinate absolute.

Parameters
string$pCoordinateStringe.g. 'A' or '1' or 'A1' Note that this value can be a row or column reference as well as a cell reference
Returns
string Absolute coordinate e.g. '$A' or '$1' or '$A$1'

Definition at line 82 of file Coordinate.php.

References PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\extractSheetTitle().

83  {
84  if (self::coordinateIsRange($pCoordinateString)) {
85  throw new Exception('Cell coordinate string can not be a range of cells');
86  }
87 
88  // Split out any worksheet name from the reference
89  [$worksheet, $pCoordinateString] = Worksheet::extractSheetTitle($pCoordinateString, true);
90  if ($worksheet > '') {
91  $worksheet .= '!';
92  }
93 
94  // Create absolute coordinate
95  if (ctype_digit($pCoordinateString)) {
96  return $worksheet . '$' . $pCoordinateString;
97  } elseif (ctype_alpha($pCoordinateString)) {
98  return $worksheet . '$' . strtoupper($pCoordinateString);
99  }
100 
101  return $worksheet . self::absoluteCoordinate($pCoordinateString);
102  }
static extractSheetTitle($pRange, $returnRange=false)
Extract worksheet title from range.
Definition: Worksheet.php:2719
+ Here is the call graph for this function:

◆ buildRange()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::buildRange ( array  $pRange)
static

Build range from coordinate strings.

Parameters
array$pRangeArray containg one or more arrays containing one or two coordinate strings
Returns
string String representation of $pRange

Definition at line 163 of file Coordinate.php.

References $i.

Referenced by PhpOffice\PhpSpreadsheet\ReferenceHelper\updateCellRange().

164  {
165  // Verify range
166  if (empty($pRange) || !is_array($pRange[0])) {
167  throw new Exception('Range does not contain any information');
168  }
169 
170  // Build range
171  $counter = count($pRange);
172  for ($i = 0; $i < $counter; ++$i) {
173  $pRange[$i] = implode(':', $pRange[$i]);
174  }
175 
176  return implode(',', $pRange);
177  }
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ columnIndexFromString()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString (   $pString)
static

Column index from string.

Parameters
string$pStringeg 'A'
Returns
int Column index (A = 1)

Definition at line 265 of file Coordinate.php.

Referenced by PhpOffice\PhpSpreadsheet\Worksheet\ColumnCellIterator\__construct(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\__construct(), PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Offset\adjustEndCellColumnForWidth(), PhpOffice\PhpSpreadsheet\Writer\Html\buildCssPerSheet(), PhpOffice\PhpSpreadsheet\Writer\Html\calculateSpansOmitRows(), PhpOffice\PhpSpreadsheet\ReferenceHelper\cellAddressInDeleteRange(), PhpOffice\PhpSpreadsheet\Calculation\LookupRef\RowColumnInformation\cellColumn(), PhpOffice\PhpSpreadsheet\Calculation\LookupRef\RowColumnInformation\COLUMN(), PhpOffice\PhpSpreadsheet\Cell\Cell\compareCells(), PhpOffice\PhpSpreadsheet\Cell\AddressHelper\convertToR1C1(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\evaluateDefinedName(), PhpOffice\PhpSpreadsheet\Writer\Html\extendRowsForCharts(), PhpOffice\PhpSpreadsheet\Writer\Html\extendRowsForChartsAndImages(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\garbageCollect(), PhpOffice\PhpSpreadsheet\Writer\Html\generateTableHeader(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getColumnDimension(), PhpOffice\PhpSpreadsheet\Shared\Xls\getDistanceX(), PhpOffice\PhpSpreadsheet\Collection\Cells\getHighestColumn(), PhpOffice\PhpSpreadsheet\ReferenceHelper\insertNewBefore(), PhpOffice\PhpSpreadsheet\Cell\Cell\isInRange(), PhpOffice\PhpSpreadsheet\Reader\Ods\load(), PhpOffice\PhpSpreadsheet\Reader\Xml\load(), PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Offset\OFFSET(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\processTokenStack(), PhpOffice\PhpSpreadsheet\Reader\Xls\readBIFF8CellAddressB(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\removeColumn(), PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator\resetEnd(), PhpOffice\PhpSpreadsheet\Worksheet\ColumnIterator\resetEnd(), PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator\resetStart(), PhpOffice\PhpSpreadsheet\Worksheet\ColumnIterator\resetStart(), PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator\seek(), PhpOffice\PhpSpreadsheet\Worksheet\ColumnIterator\seek(), PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\setRange(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\shrinkRangeToFit(), PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\testColumnInRange(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateCellReferencesAllWorksheets(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateColumnRangesAllWorksheets(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateFormulaReferences(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateSingleCellReference(), PhpOffice\PhpSpreadsheet\Writer\Ods\Settings\write(), PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook\writeAllDefinedNamesBiff8(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeBreaks(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeBreaks(), PhpOffice\PhpSpreadsheet\Writer\Ods\Content\writeCellMerge(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeCols(), PhpOffice\PhpSpreadsheet\Writer\Ods\Content\writeRows(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeSelection(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeSheetData(), and PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeSheetViews().

266  {
267  // Using a lookup cache adds a slight memory overhead, but boosts speed
268  // caching using a static within the method is faster than a class static,
269  // though it's additional memory overhead
270  static $indexCache = [];
271 
272  if (isset($indexCache[$pString])) {
273  return $indexCache[$pString];
274  }
275  // It's surprising how costly the strtoupper() and ord() calls actually are, so we use a lookup array rather than use ord()
276  // and make it case insensitive to get rid of the strtoupper() as well. Because it's a static, there's no significant
277  // memory overhead either
278  static $columnLookup = [
279  'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13,
280  'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26,
281  'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8, 'i' => 9, 'j' => 10, 'k' => 11, 'l' => 12, 'm' => 13,
282  'n' => 14, 'o' => 15, 'p' => 16, 'q' => 17, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'v' => 22, 'w' => 23, 'x' => 24, 'y' => 25, 'z' => 26,
283  ];
284 
285  // We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString
286  // for improved performance
287  if (isset($pString[0])) {
288  if (!isset($pString[1])) {
289  $indexCache[$pString] = $columnLookup[$pString];
290 
291  return $indexCache[$pString];
292  } elseif (!isset($pString[2])) {
293  $indexCache[$pString] = $columnLookup[$pString[0]] * 26 + $columnLookup[$pString[1]];
294 
295  return $indexCache[$pString];
296  } elseif (!isset($pString[3])) {
297  $indexCache[$pString] = $columnLookup[$pString[0]] * 676 + $columnLookup[$pString[1]] * 26 + $columnLookup[$pString[2]];
298 
299  return $indexCache[$pString];
300  }
301  }
302 
303  throw new Exception('Column string index can not be ' . ((isset($pString[0])) ? 'longer than 3 characters' : 'empty'));
304  }
+ Here is the caller graph for this function:

◆ coordinateFromString()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::coordinateFromString (   $pCoordinateString)
static

Coordinate from string.

Parameters
string$pCoordinateStringeg: 'A1'
Returns
array{0: string, 1: string} Array containing column and row (indexes 0 and 1)

Definition at line 32 of file Coordinate.php.

Referenced by PhpOffice\PhpSpreadsheet\ReferenceHelper\adjustColumnDimensions(), PhpOffice\PhpSpreadsheet\ReferenceHelper\adjustRowDimensions(), PhpOffice\PhpSpreadsheet\Style\Style\applyFromArray(), PhpOffice\PhpSpreadsheet\ReferenceHelper\cellAddressInDeleteRange(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\createNewCell(), PhpOffice\PhpSpreadsheet\Writer\Html\extendRowsForCharts(), PhpOffice\PhpSpreadsheet\Writer\Html\extendRowsForChartsAndImages(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\extractNamedRange(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\freezePane(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\fromArray(), PhpOffice\PhpSpreadsheet\Reader\Xlsx\getFromZipArchive(), PhpOffice\PhpSpreadsheet\Reader\Xls\load(), PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Offset\OFFSET(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\processTokenStack(), PhpOffice\PhpSpreadsheet\Reader\Xls\readBIFF8CellAddressB(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateCellRange(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateFormulaReferences(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateSingleCellReference(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeBreaks(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeBreaks(), PhpOffice\PhpSpreadsheet\Writer\Ods\Content\writeCellMerge(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeSelection(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeSheetData(), and PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeSheetViews().

33  {
34  if (preg_match(self::A1_COORDINATE_REGEX, $pCoordinateString, $matches)) {
35  return [$matches['absolute_col'] . $matches['col_ref'], $matches['absolute_row'] . $matches['row_ref']];
36  } elseif (self::coordinateIsRange($pCoordinateString)) {
37  throw new Exception('Cell coordinate string can not be a range of cells');
38  } elseif ($pCoordinateString == '') {
39  throw new Exception('Cell coordinate can not be zero-length string');
40  }
41 
42  throw new Exception('Invalid cell coordinate ' . $pCoordinateString);
43  }
+ Here is the caller graph for this function:

◆ coordinateIsRange()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::coordinateIsRange (   $coord)
static

Checks if a coordinate represents a range of cells.

Parameters
string$coordeg: 'A1' or 'A1:A2' or 'A1:A2,C1:C2'
Returns
bool Whether the coordinate represents a range of cells

Definition at line 69 of file Coordinate.php.

Referenced by PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\freezePane(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getComment(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getWorksheetAndCoordinate(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\setSelectedCells(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateCellRange(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateCellReference(), and PhpOffice\PhpSpreadsheet\ReferenceHelper\updateSingleCellReference().

70  {
71  return (strpos($coord, ':') !== false) || (strpos($coord, ',') !== false);
72  }
+ Here is the caller graph for this function:

◆ extractAllCellReferencesInRange()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::extractAllCellReferencesInRange (   $cellRange)
static

Extract all cell references in range, which may be comprised of multiple cell ranges.

Parameters
string$cellRangeRange: e.g. 'A1' or 'A1:C10' or 'A1:E10,A20:E25' or 'A1:E5 C3:G7' or 'A1:C1,A3:C3 B1:C3'
Returns
array Array containing single cell references

Definition at line 338 of file Coordinate.php.

Referenced by PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\calculateColumnWidths(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\extractCellRange(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\extractNamedRange(), PhpOffice\PhpSpreadsheet\NamedRange\getCellsInRange(), PhpOffice\PhpSpreadsheet\Reader\Xlsx\DataValidations\load(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\mergeCells(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTd(), PhpOffice\PhpSpreadsheet\Reader\Xls\readDataValidation(), PhpOffice\PhpSpreadsheet\Reader\Xls\readHyperLink(), and PhpOffice\PhpSpreadsheet\Reader\Xlsx\Hyperlinks\setHyperlink().

338  : array
339  {
340  [$ranges, $operators] = self::getCellBlocksFromRangeString($cellRange);
341 
342  $cells = [];
343  foreach ($ranges as $range) {
344  $cells[] = self::getReferencesForCellBlock($range);
345  }
346 
347  $cells = self::processRangeSetOperators($operators, $cells);
348 
349  if (empty($cells)) {
350  return [];
351  }
352 
353  $cellList = array_merge(...$cells);
354  $cellList = self::sortCellReferenceArray($cellList);
355 
356  return $cellList;
357  }
+ Here is the caller graph for this function:

◆ getCellBlocksFromRangeString()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::getCellBlocksFromRangeString (   $rangeString)
staticprivate

Get the individual cell blocks from a range string, removing any $ characters.

then splitting by operators and returning an array with ranges and operators.

Parameters
string$rangeString
Returns
array[]

Definition at line 540 of file Coordinate.php.

541  {
542  $rangeString = str_replace('$', '', strtoupper($rangeString));
543 
544  // split range sets on intersection (space) or union (,) operators
545  $tokens = preg_split('/([ ,])/', $rangeString, -1, PREG_SPLIT_DELIM_CAPTURE);
546  // separate the range sets and the operators into arrays
547  $split = array_chunk($tokens, 2);
548  $ranges = array_column($split, 0);
549  $operators = array_column($split, 1);
550 
551  return [$ranges, $operators];
552  }

◆ getRangeBoundaries()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::getRangeBoundaries (   $pRange)
static

Calculate range boundaries.

Parameters
string$pRangeCell range (e.g. A1:A1)
Returns
array Range coordinates [Start Cell, End Cell] where Start Cell and End Cell are arrays [Column ID, Row Number]

Definition at line 238 of file Coordinate.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Xls\includeCellRangeFiltered(), and PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\shrinkRangeToFit().

239  {
240  // Ensure $pRange is a valid range
241  if (empty($pRange)) {
242  $pRange = self::DEFAULT_RANGE;
243  }
244 
245  // Uppercase coordinate
246  $pRange = strtoupper($pRange);
247 
248  // Extract range
249  if (strpos($pRange, ':') === false) {
250  $rangeA = $rangeB = $pRange;
251  } else {
252  [$rangeA, $rangeB] = explode(':', $pRange);
253  }
254 
255  return [self::coordinateFromString($rangeA), self::coordinateFromString($rangeB)];
256  }
+ Here is the caller graph for this function:

◆ getReferencesForCellBlock()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::getReferencesForCellBlock (   $cellBlock)
staticprivate

Get all cell references for an individual cell block.

Parameters
string$cellBlockA cell range e.g. A4:B5
Returns
array All individual cells in that range

Definition at line 399 of file Coordinate.php.

400  {
401  $returnValue = [];
402 
403  // Single cell?
404  if (!self::coordinateIsRange($cellBlock)) {
405  return (array) $cellBlock;
406  }
407 
408  // Range...
409  $ranges = self::splitRange($cellBlock);
410  foreach ($ranges as $range) {
411  // Single cell?
412  if (!isset($range[1])) {
413  $returnValue[] = $range[0];
414 
415  continue;
416  }
417 
418  // Range...
419  [$rangeStart, $rangeEnd] = $range;
420  [$startColumn, $startRow] = self::coordinateFromString($rangeStart);
421  [$endColumn, $endRow] = self::coordinateFromString($rangeEnd);
422  $startColumnIndex = self::columnIndexFromString($startColumn);
423  $endColumnIndex = self::columnIndexFromString($endColumn);
424  ++$endColumnIndex;
425 
426  // Current data
427  $currentColumnIndex = $startColumnIndex;
428  $currentRow = $startRow;
429 
430  self::validateRange($cellBlock, $startColumnIndex, $endColumnIndex, $currentRow, $endRow);
431 
432  // Loop cells
433  while ($currentColumnIndex < $endColumnIndex) {
434  while ($currentRow <= $endRow) {
435  $returnValue[] = self::stringFromColumnIndex($currentColumnIndex) . $currentRow;
436  ++$currentRow;
437  }
438  ++$currentColumnIndex;
439  $currentRow = $startRow;
440  }
441  }
442 
443  return $returnValue;
444  }

◆ indexesFromString()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::indexesFromString ( string  $coordinates)
static

Get indexes from a string coordinates.

Parameters
string$coordinateseg: 'A1', '$B$12'
Returns
array{0: int, 1: int} Array containing column index and row index (indexes 0 and 1)

Definition at line 52 of file Coordinate.php.

References $row.

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\__construct(), PhpOffice\PhpSpreadsheet\Style\Style\applyFromArray(), PhpOffice\PhpSpreadsheet\Writer\Html\calculateSpans(), PhpOffice\PhpSpreadsheet\Reader\Xlsx\castToFormula(), PhpOffice\PhpSpreadsheet\Writer\Xls\Escher\close(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\createNewCell(), PhpOffice\PhpSpreadsheet\Writer\Html\generateSheetData(), PhpOffice\PhpSpreadsheet\ReferenceHelper\insertNewBefore(), PhpOffice\PhpSpreadsheet\Shared\Xls\oneAnchor2twoAnchor(), PhpOffice\PhpSpreadsheet\Reader\Xls\readBIFF8CellRangeAddressB(), PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook\writeAllDefinedNamesBiff8(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeBIFF8CellRangeAddressFixed(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Drawing\writeChart(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Drawing\writeDrawing(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeMergedCells(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writePanes(), and PhpOffice\PhpSpreadsheet\Writer\Xlsx\Comments\writeVMLComment().

52  : array
53  {
54  [$col, $row] = self::coordinateFromString($coordinates);
55 
56  return [
57  self::columnIndexFromString(ltrim($col, '$')),
58  (int) ltrim($row, '$'),
59  ];
60  }
$row
+ Here is the caller graph for this function:

◆ mergeRangesInCollection()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::mergeRangesInCollection ( array  $pCoordCollection)
static

Convert an associative array of single cell coordinates to values to an associative array of cell ranges to values.

Only adjacent cell coordinates with the same value will be merged. If the value is an object, it must implement the method getHashCode().

For example, this function converts:

[ 'A1' => 'x', 'A2' => 'x', 'A3' => 'x', 'A4' => 'y' ]

to:

[ 'A1:A3' => 'x', 'A4' => 'y' ]

Parameters
array$pCoordCollectionassociative array mapping coordinates to values
Returns
array associative array mapping coordinate ranges to valuea

Definition at line 463 of file Coordinate.php.

References $row.

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeDataValidations().

464  {
465  $hashedValues = [];
466  $mergedCoordCollection = [];
467 
468  foreach ($pCoordCollection as $coord => $value) {
469  if (self::coordinateIsRange($coord)) {
470  $mergedCoordCollection[$coord] = $value;
471 
472  continue;
473  }
474 
475  [$column, $row] = self::coordinateFromString($coord);
476  $row = (int) (ltrim($row, '$'));
477  $hashCode = $column . '-' . (is_object($value) ? $value->getHashCode() : $value);
478 
479  if (!isset($hashedValues[$hashCode])) {
480  $hashedValues[$hashCode] = (object) [
481  'value' => $value,
482  'col' => $column,
483  'rows' => [$row],
484  ];
485  } else {
486  $hashedValues[$hashCode]->rows[] = $row;
487  }
488  }
489 
490  ksort($hashedValues);
491 
492  foreach ($hashedValues as $hashedValue) {
493  sort($hashedValue->rows);
494  $rowStart = null;
495  $rowEnd = null;
496  $ranges = [];
497 
498  foreach ($hashedValue->rows as $row) {
499  if ($rowStart === null) {
500  $rowStart = $row;
501  $rowEnd = $row;
502  } elseif ($rowEnd === $row - 1) {
503  $rowEnd = $row;
504  } else {
505  if ($rowStart == $rowEnd) {
506  $ranges[] = $hashedValue->col . $rowStart;
507  } else {
508  $ranges[] = $hashedValue->col . $rowStart . ':' . $hashedValue->col . $rowEnd;
509  }
510 
511  $rowStart = $row;
512  $rowEnd = $row;
513  }
514  }
515 
516  if ($rowStart !== null) {
517  if ($rowStart == $rowEnd) {
518  $ranges[] = $hashedValue->col . $rowStart;
519  } else {
520  $ranges[] = $hashedValue->col . $rowStart . ':' . $hashedValue->col . $rowEnd;
521  }
522  }
523 
524  foreach ($ranges as $range) {
525  $mergedCoordCollection[$range] = $hashedValue->value;
526  }
527  }
528 
529  return $mergedCoordCollection;
530  }
$row
+ Here is the caller graph for this function:

◆ processRangeSetOperators()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::processRangeSetOperators ( array  $operators,
array  $cells 
)
staticprivate

Definition at line 359 of file Coordinate.php.

359  : array
360  {
361  $operatorCount = count($operators);
362  for ($offset = 0; $offset < $operatorCount; ++$offset) {
363  $operator = $operators[$offset];
364  if ($operator !== ' ') {
365  continue;
366  }
367 
368  $cells[$offset] = array_intersect($cells[$offset], $cells[$offset + 1]);
369  unset($operators[$offset], $cells[$offset + 1]);
370  $operators = array_values($operators);
371  $cells = array_values($cells);
372  --$offset;
373  --$operatorCount;
374  }
375 
376  return $cells;
377  }

◆ rangeBoundaries()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::rangeBoundaries (   $pRange)
static

Calculate range boundaries.

Parameters
string$pRangeCell range (e.g. A1:A1)
Returns
array Range coordinates [Start Cell, End Cell] where Start Cell and End Cell are arrays (Column Number, Row Number)

Definition at line 187 of file Coordinate.php.

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xls\buildWorksheetEschers(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\duplicateConditionalStyle(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\duplicateStyle(), PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\getColumnByOffset(), PhpOffice\PhpSpreadsheet\ReferenceHelper\insertNewBefore(), PhpOffice\PhpSpreadsheet\Cell\Cell\isInRange(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\rangeToArray(), PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\setRange(), PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\showHideRows(), PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\testColumnInRange(), PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook\writeAllDefinedNamesBiff8(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeAutoFilterInfo(), and PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeCFHeader().

188  {
189  // Ensure $pRange is a valid range
190  if (empty($pRange)) {
191  $pRange = self::DEFAULT_RANGE;
192  }
193 
194  // Uppercase coordinate
195  $pRange = strtoupper($pRange);
196 
197  // Extract range
198  if (strpos($pRange, ':') === false) {
199  $rangeA = $rangeB = $pRange;
200  } else {
201  [$rangeA, $rangeB] = explode(':', $pRange);
202  }
203 
204  // Calculate range outer borders
205  $rangeStart = self::coordinateFromString($rangeA);
206  $rangeEnd = self::coordinateFromString($rangeB);
207 
208  // Translate column into index
209  $rangeStart[0] = self::columnIndexFromString($rangeStart[0]);
210  $rangeEnd[0] = self::columnIndexFromString($rangeEnd[0]);
211 
212  return [$rangeStart, $rangeEnd];
213  }
+ Here is the caller graph for this function:

◆ rangeDimension()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::rangeDimension (   $pRange)
static

Calculate range dimension.

Parameters
string$pRangeCell range (e.g. A1:A1)
Returns
array Range dimension (width, height)

Definition at line 222 of file Coordinate.php.

Referenced by PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\calculateColumnWidths(), and PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues\refresh().

223  {
224  // Calculate range outer borders
225  [$rangeStart, $rangeEnd] = self::rangeBoundaries($pRange);
226 
227  return [($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1)];
228  }
+ Here is the caller graph for this function:

◆ sortCellReferenceArray()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::sortCellReferenceArray ( array  $cellList)
staticprivate

Definition at line 379 of file Coordinate.php.

References $row.

379  : array
380  {
381  // Sort the result by column and row
382  $sortKeys = [];
383  foreach ($cellList as $coord) {
384  [$column, $row] = sscanf($coord, '%[A-Z]%d');
385  $sortKeys[sprintf('%3s%09d', $column, $row)] = $coord;
386  }
387  ksort($sortKeys);
388 
389  return array_values($sortKeys);
390  }
$row

◆ splitRange()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::splitRange (   $pRange)
static

Split range into coordinate strings.

Parameters
string$pRangee.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4'
Returns
array Array containing one or more arrays containing one or two coordinate strings e.g. ['B4','D9'] or [['B4','D9'], ['H2','O11']] or ['B4']

Definition at line 140 of file Coordinate.php.

References $i.

Referenced by PhpOffice\PhpSpreadsheet\Writer\Html\calculateSpans(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\extractNamedRange(), PhpOffice\PhpSpreadsheet\Cell\Cell\isMergeRangeValueCell(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\setSelectedCells(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateCellRange(), PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook\writeAllDefinedNamesBiff8(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeAutoFilter(), PhpOffice\PhpSpreadsheet\Writer\Ods\Content\writeCellMerge(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeMergedCells(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\DefinedNames\writeNamedRangeForAutofilter(), and PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeSelection().

141  {
142  // Ensure $pRange is a valid range
143  if (empty($pRange)) {
144  $pRange = self::DEFAULT_RANGE;
145  }
146 
147  $exploded = explode(',', $pRange);
148  $counter = count($exploded);
149  for ($i = 0; $i < $counter; ++$i) {
150  $exploded[$i] = explode(':', $exploded[$i]);
151  }
152 
153  return $exploded;
154  }
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ stringFromColumnIndex()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex (   $columnIndex)
static

String from column index.

Parameters
int$columnIndexColumn index (A = 1)
Returns
string

Definition at line 313 of file Coordinate.php.

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\__construct(), PhpOffice\PhpSpreadsheet\Reader\Slk\addFonts(), PhpOffice\PhpSpreadsheet\Reader\Slk\addFormats(), PhpOffice\PhpSpreadsheet\Worksheet\PageSetup\addPrintAreaByColumnAndRow(), PhpOffice\PhpSpreadsheet\Reader\Slk\addStyle(), PhpOffice\PhpSpreadsheet\Reader\Slk\addWidth(), PhpOffice\PhpSpreadsheet\Style\Style\applyFromArray(), PhpOffice\PhpSpreadsheet\Writer\Xls\buildWorksheetEschers(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\cellExistsByColumnAndRow(), PhpOffice\PhpSpreadsheet\Reader\Xlsx\PageSetup\columnBreaks(), PhpOffice\PhpSpreadsheet\Cell\AddressHelper\convertToA1(), PhpOffice\PhpSpreadsheet\Worksheet\ColumnIterator\current(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\duplicateConditionalStyle(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\duplicateStyle(), PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Address\formatAsA1(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\freezePaneByColumnAndRow(), PhpOffice\PhpSpreadsheet\Writer\Html\generateRow(), PhpOffice\PhpSpreadsheet\Writer\Html\generateRowCellCss(), PhpOffice\PhpSpreadsheet\Writer\Html\generateSheetData(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getCellOrNull(), PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\getColumnByOffset(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getColumnDimensionByColumn(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getCommentByColumnAndRow(), PhpOffice\PhpSpreadsheet\Shared\Xls\getDistanceX(), PhpOffice\PhpSpreadsheet\Reader\Xlsx\getFromZipArchive(), PhpOffice\PhpSpreadsheet\Collection\Cells\getHighestColumn(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getHighestColumn(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getStyleByColumnAndRow(), PhpOffice\PhpSpreadsheet\ReferenceHelper\insertNewBefore(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\insertNewColumnBeforeByIndex(), PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator\key(), PhpOffice\PhpSpreadsheet\Worksheet\ColumnIterator\key(), PhpOffice\PhpSpreadsheet\Reader\Slk\listWorksheetInfo(), PhpOffice\PhpSpreadsheet\Reader\Ods\listWorksheetInfo(), PhpOffice\PhpSpreadsheet\Reader\Gnumeric\listWorksheetInfo(), PhpOffice\PhpSpreadsheet\Reader\Xml\listWorksheetInfo(), PhpOffice\PhpSpreadsheet\Reader\Csv\listWorksheetInfo(), PhpOffice\PhpSpreadsheet\Reader\Xls\listWorksheetInfo(), PhpOffice\PhpSpreadsheet\Reader\Xlsx\listWorksheetNames(), PhpOffice\PhpSpreadsheet\Reader\Ods\load(), PhpOffice\PhpSpreadsheet\Reader\Xml\load(), PhpOffice\PhpSpreadsheet\Reader\Gnumeric\loadIntoExisting(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\mergeCellsByColumnAndRow(), PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Offset\OFFSET(), PhpOffice\PhpSpreadsheet\Shared\Xls\oneAnchor2twoAnchor(), PhpOffice\PhpSpreadsheet\Reader\Xlsx\SheetViews\pane(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\positionImage(), PhpOffice\PhpSpreadsheet\Reader\Slk\processCRecord(), PhpOffice\PhpSpreadsheet\Reader\Slk\processFormula(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\processTokenStack(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\protectCellsByColumnAndRow(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\rangeToArray(), PhpOffice\PhpSpreadsheet\Reader\Xls\readBIFF5CellRangeAddressFixed(), PhpOffice\PhpSpreadsheet\Reader\Xls\readBIFF8CellAddress(), PhpOffice\PhpSpreadsheet\Reader\Xls\readBIFF8CellAddressB(), PhpOffice\PhpSpreadsheet\Reader\Xls\readBIFF8CellRangeAddress(), PhpOffice\PhpSpreadsheet\Reader\Xls\readBIFF8CellRangeAddressB(), PhpOffice\PhpSpreadsheet\Reader\Xls\readBIFF8CellRangeAddressFixed(), PhpOffice\PhpSpreadsheet\Reader\Xls\readBlank(), PhpOffice\PhpSpreadsheet\Reader\Xls\readBoolErr(), PhpOffice\PhpSpreadsheet\Reader\Xls\Escher\readClientAnchor(), PhpOffice\PhpSpreadsheet\Reader\Xlsx\ColumnAndRowAttributes\readColumnAttributes(), PhpOffice\PhpSpreadsheet\Reader\Xls\readFormula(), PhpOffice\PhpSpreadsheet\Reader\Xls\readLabel(), PhpOffice\PhpSpreadsheet\Reader\Xls\readLabelSst(), PhpOffice\PhpSpreadsheet\Reader\Xls\readMulBlank(), PhpOffice\PhpSpreadsheet\Reader\Xls\readMulRk(), PhpOffice\PhpSpreadsheet\Reader\Xls\readNumber(), PhpOffice\PhpSpreadsheet\Reader\Xls\readPane(), PhpOffice\PhpSpreadsheet\Reader\Xls\readRk(), PhpOffice\PhpSpreadsheet\Reader\Gnumeric\Styles\readStyleRange(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\removeColumn(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\removeColumnByIndex(), PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator\resetStart(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\setAutoFilterByColumnAndRow(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\setBreakByColumnAndRow(), PhpOffice\PhpSpreadsheet\Reader\Gnumeric\setColumnInvisible(), PhpOffice\PhpSpreadsheet\Reader\Gnumeric\setColumnWidth(), PhpOffice\PhpSpreadsheet\Worksheet\PageSetup\setPrintAreaByColumnAndRow(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\setSelectedCellByColumnAndRow(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\shrinkRangeToFit(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\unmergeCellsByColumnAndRow(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\unprotectCellsByColumnAndRow(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateCellReferencesAllWorksheets(), PhpOffice\PhpSpreadsheet\ReferenceHelper\updateColumnRangesAllWorksheets(), and PhpOffice\PhpSpreadsheet\ReferenceHelper\updateSingleCellReference().

314  {
315  static $indexCache = [];
316 
317  if (!isset($indexCache[$columnIndex])) {
318  $indexValue = $columnIndex;
319  $base26 = null;
320  do {
321  $characterValue = ($indexValue % 26) ?: 26;
322  $indexValue = ($indexValue - $characterValue) / 26;
323  $base26 = chr($characterValue + 64) . ($base26 ?: '');
324  } while ($indexValue > 0);
325  $indexCache[$columnIndex] = $base26;
326  }
327 
328  return $indexCache[$columnIndex];
329  }
+ Here is the caller graph for this function:

◆ validateRange()

static PhpOffice\PhpSpreadsheet\Cell\Coordinate::validateRange (   $cellBlock,
  $startColumnIndex,
  $endColumnIndex,
  $currentRow,
  $endRow 
)
staticprivate

Check that the given range is valid, i.e.

that the start column and row are not greater than the end column and row.

Parameters
string$cellBlockThe original range, for displaying a meaningful error message
int$startColumnIndex
int$endColumnIndex
int$currentRow
int$endRow

Definition at line 564 of file Coordinate.php.

564  : void
565  {
566  if ($startColumnIndex >= $endColumnIndex || $currentRow > $endRow) {
567  throw new Exception('Invalid range: "' . $cellBlock . '"');
568  }
569  }

Field Documentation

◆ A1_COORDINATE_REGEX

const PhpOffice\PhpSpreadsheet\Cell\Coordinate::A1_COORDINATE_REGEX = '/^(?<absolute_col>\$?)(?<col_ref>[A-Z]{1,3})(?<absolute_row>\$?)(?<row_ref>\d{1,7})$/i'

◆ DEFAULT_RANGE

const PhpOffice\PhpSpreadsheet\Cell\Coordinate::DEFAULT_RANGE = 'A1:A1'

Definition at line 23 of file Coordinate.php.


The documentation for this class was generated from the following file: