ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Collection\Cells Class Reference
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Collection\Cells:

Public Member Functions

 __construct (Worksheet $parent, CacheInterface $cache)
 Initialise this new cell collection. More...
 
 getParent ()
 Return the parent worksheet for this cell collection. More...
 
 has ($pCoord)
 Whether the collection holds a cell for the given coordinate. More...
 
 update (Cell $cell)
 Add or update a cell in the collection. More...
 
 delete ($pCoord)
 Delete a cell in cache identified by coordinate. More...
 
 getCoordinates ()
 Get a list of all cell coordinates currently held in the collection. More...
 
 getSortedCoordinates ()
 Get a sorted list of all cell coordinates currently held in the collection by row and column. More...
 
 getHighestRowAndColumn ()
 Get highest worksheet column and highest row that have cell records. More...
 
 getCurrentCoordinate ()
 Return the cell coordinate of the currently active cell object. More...
 
 getCurrentColumn ()
 Return the column coordinate of the currently active cell object. More...
 
 getCurrentRow ()
 Return the row coordinate of the currently active cell object. More...
 
 getHighestColumn ($row=null)
 Get highest worksheet column. More...
 
 getHighestRow ($column=null)
 Get highest worksheet row. More...
 
 cloneCellCollection (Worksheet $parent)
 Clone the cell collection. More...
 
 removeRow ($row)
 Remove a row, deleting all cells in that row. More...
 
 removeColumn ($column)
 Remove a column, deleting all cells in that column. More...
 
 add ($pCoord, Cell $cell)
 Add or update a cell identified by its coordinate into the collection. More...
 
 get ($pCoord)
 Get cell at a specific coordinate. More...
 
 unsetWorksheetCells ()
 Clear the cell collection and disconnect from our parent. More...
 
 __destruct ()
 Destroy this cell collection. More...
 

Private Member Functions

 getUniqueID ()
 Generate a unique ID for cache referencing. More...
 
 storeCurrentCell ()
 Store cell data in cache for the current cell object if it's "dirty", and the 'nullify' the current cell object. More...
 
 getAllCacheKeys ()
 Returns all known cache keys. More...
 

Private Attributes

 $cache
 
 $parent
 
 $currentCell
 
 $currentCoordinate
 
 $currentCellIsDirty = false
 
 $index = []
 
 $cachePrefix
 

Detailed Description

Definition at line 12 of file Cells.php.

Constructor & Destructor Documentation

◆ __construct()

PhpOffice\PhpSpreadsheet\Collection\Cells::__construct ( Worksheet  $parent,
CacheInterface  $cache 
)

Initialise this new cell collection.

Parameters
Worksheet$parentThe worksheet for this cell collection

Definition at line 66 of file Cells.php.

References PhpOffice\PhpSpreadsheet\Collection\Cells\$cache, PhpOffice\PhpSpreadsheet\Collection\Cells\$parent, and PhpOffice\PhpSpreadsheet\Collection\Cells\getUniqueID().

67  {
68  // Set our parent worksheet.
69  // This is maintained here to facilitate re-attaching it to Cell objects when
70  // they are woken from a serialized state
71  $this->parent = $parent;
72  $this->cache = $cache;
73  $this->cachePrefix = $this->getUniqueID();
74  }
getUniqueID()
Generate a unique ID for cache referencing.
Definition: Cells.php:299
+ Here is the call graph for this function:

◆ __destruct()

PhpOffice\PhpSpreadsheet\Collection\Cells::__destruct ( )

Destroy this cell collection.

Definition at line 482 of file Cells.php.

References PhpOffice\PhpSpreadsheet\Collection\Cells\getAllCacheKeys().

Referenced by PhpOffice\PhpSpreadsheet\Collection\Cells\storeCurrentCell(), and PhpOffice\PhpSpreadsheet\Collection\Cells\unsetWorksheetCells().

483  {
484  $this->cache->deleteMultiple($this->getAllCacheKeys());
485  }
getAllCacheKeys()
Returns all known cache keys.
Definition: Cells.php:492
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

◆ add()

PhpOffice\PhpSpreadsheet\Collection\Cells::add (   $pCoord,
Cell  $cell 
)

Add or update a cell identified by its coordinate into the collection.

Parameters
string$pCoordCoordinate of the cell to update
Cell$cellCell to update
Returns
Cell

Definition at line 410 of file Cells.php.

References PhpOffice\PhpSpreadsheet\Collection\Cells\storeCurrentCell().

Referenced by PhpOffice\PhpSpreadsheet\Collection\Cells\update().

411  {
412  if ($pCoord !== $this->currentCoordinate) {
413  $this->storeCurrentCell();
414  }
415  $this->index[$pCoord] = true;
416 
417  $this->currentCoordinate = $pCoord;
418  $this->currentCell = $cell;
419  $this->currentCellIsDirty = true;
420 
421  return $cell;
422  }
storeCurrentCell()
Store cell data in cache for the current cell object if it's "dirty", and the 'nullify' the current c...
Definition: Cells.php:384
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cloneCellCollection()

PhpOffice\PhpSpreadsheet\Collection\Cells::cloneCellCollection ( Worksheet  $parent)

Clone the cell collection.

Parameters
Worksheet$parentThe new worksheet that we're copying to
Returns
self

Definition at line 311 of file Cells.php.

References PhpOffice\PhpSpreadsheet\Collection\Cells\$parent, and PhpOffice\PhpSpreadsheet\Collection\Cells\storeCurrentCell().

312  {
313  $this->storeCurrentCell();
314  $newCollection = clone $this;
315 
316  $newCollection->parent = $parent;
317  if (($newCollection->currentCell !== null) && (is_object($newCollection->currentCell))) {
318  $newCollection->currentCell->attach($this);
319  }
320 
321  // Get old values
322  $oldKeys = $newCollection->getAllCacheKeys();
323  $oldValues = $newCollection->cache->getMultiple($oldKeys);
324  $newValues = [];
325  $oldCachePrefix = $newCollection->cachePrefix;
326 
327  // Change prefix
328  $newCollection->cachePrefix = $newCollection->getUniqueID();
329  foreach ($oldValues as $oldKey => $value) {
330  $newValues[str_replace($oldCachePrefix, $newCollection->cachePrefix, $oldKey)] = clone $value;
331  }
332 
333  // Store new values
334  $stored = $newCollection->cache->setMultiple($newValues);
335  if (!$stored) {
336  $newCollection->__destruct();
337 
338  throw new PhpSpreadsheetException('Failed to copy cells in cache');
339  }
340 
341  return $newCollection;
342  }
storeCurrentCell()
Store cell data in cache for the current cell object if it's "dirty", and the 'nullify' the current c...
Definition: Cells.php:384
+ Here is the call graph for this function:

◆ delete()

PhpOffice\PhpSpreadsheet\Collection\Cells::delete (   $pCoord)

Delete a cell in cache identified by coordinate.

Parameters
string$pCoordCoordinate of the cell to delete

Definition at line 120 of file Cells.php.

120  : void
121  {
122  if ($pCoord === $this->currentCoordinate && $this->currentCell !== null) {
123  $this->currentCell->detach();
124  $this->currentCoordinate = null;
125  $this->currentCell = null;
126  $this->currentCellIsDirty = false;
127  }
128 
129  unset($this->index[$pCoord]);
130 
131  // Delete the entry from cache
132  $this->cache->delete($this->cachePrefix . $pCoord);
133  }

◆ get()

PhpOffice\PhpSpreadsheet\Collection\Cells::get (   $pCoord)

Get cell at a specific coordinate.

Parameters
string$pCoordCoordinate of the cell
Returns
null|Cell Cell that was found, or null if not found

Definition at line 431 of file Cells.php.

References PhpOffice\PhpSpreadsheet\Collection\Cells\$currentCell, PhpOffice\PhpSpreadsheet\Collection\Cells\has(), and PhpOffice\PhpSpreadsheet\Collection\Cells\storeCurrentCell().

432  {
433  if ($pCoord === $this->currentCoordinate) {
434  return $this->currentCell;
435  }
436  $this->storeCurrentCell();
437 
438  // Return null if requested entry doesn't exist in collection
439  if (!$this->has($pCoord)) {
440  return null;
441  }
442 
443  // Check if the entry that has been requested actually exists
444  $cell = $this->cache->get($this->cachePrefix . $pCoord);
445  if ($cell === null) {
446  throw new PhpSpreadsheetException("Cell entry {$pCoord} no longer exists in cache. This probably means that the cache was cleared by someone else.");
447  }
448 
449  // Set current entry to the requested entry
450  $this->currentCoordinate = $pCoord;
451  $this->currentCell = $cell;
452  // Re-attach this as the cell's parent
453  $this->currentCell->attach($this);
454 
455  // Return requested entry
456  return $this->currentCell;
457  }
storeCurrentCell()
Store cell data in cache for the current cell object if it's "dirty", and the 'nullify' the current c...
Definition: Cells.php:384
has($pCoord)
Whether the collection holds a cell for the given coordinate.
Definition: Cells.php:93
+ Here is the call graph for this function:

◆ getAllCacheKeys()

PhpOffice\PhpSpreadsheet\Collection\Cells::getAllCacheKeys ( )
private

Returns all known cache keys.

Returns
Generator|string[]

Definition at line 492 of file Cells.php.

References PhpOffice\PhpSpreadsheet\Collection\Cells\getCoordinates().

Referenced by PhpOffice\PhpSpreadsheet\Collection\Cells\__destruct().

493  {
494  foreach ($this->getCoordinates() as $coordinate) {
495  yield $this->cachePrefix . $coordinate;
496  }
497  }
getCoordinates()
Get a list of all cell coordinates currently held in the collection.
Definition: Cells.php:140
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCoordinates()

PhpOffice\PhpSpreadsheet\Collection\Cells::getCoordinates ( )

◆ getCurrentColumn()

PhpOffice\PhpSpreadsheet\Collection\Cells::getCurrentColumn ( )

Return the column coordinate of the currently active cell object.

Returns
string

Definition at line 207 of file Cells.php.

References $row.

208  {
209  $column = '';
210  $row = 0;
211 
212  sscanf($this->currentCoordinate, '%[A-Z]%d', $column, $row);
213 
214  return $column;
215  }
$row

◆ getCurrentCoordinate()

PhpOffice\PhpSpreadsheet\Collection\Cells::getCurrentCoordinate ( )

Return the cell coordinate of the currently active cell object.

Returns
string

Definition at line 197 of file Cells.php.

References PhpOffice\PhpSpreadsheet\Collection\Cells\$currentCoordinate.

◆ getCurrentRow()

PhpOffice\PhpSpreadsheet\Collection\Cells::getCurrentRow ( )

Return the row coordinate of the currently active cell object.

Returns
int

Definition at line 222 of file Cells.php.

References $row.

223  {
224  $column = '';
225  $row = 0;
226 
227  sscanf($this->currentCoordinate, '%[A-Z]%d', $column, $row);
228 
229  return (int) $row;
230  }
$row

◆ getHighestColumn()

PhpOffice\PhpSpreadsheet\Collection\Cells::getHighestColumn (   $row = null)

Get highest worksheet column.

Parameters
string$rowReturn the highest column for the specified row, or the highest column of any row if no row number is passed
Returns
string Highest column name

Definition at line 240 of file Cells.php.

References $c, $r, $row, PhpOffice\PhpSpreadsheet\Cell\Coordinate\columnIndexFromString(), PhpOffice\PhpSpreadsheet\Collection\Cells\getCoordinates(), PhpOffice\PhpSpreadsheet\Collection\Cells\getHighestRowAndColumn(), and PhpOffice\PhpSpreadsheet\Cell\Coordinate\stringFromColumnIndex().

241  {
242  if ($row === null) {
243  $colRow = $this->getHighestRowAndColumn();
244 
245  return $colRow['column'];
246  }
247 
248  $columnList = [1];
249  foreach ($this->getCoordinates() as $coord) {
250  $c = '';
251  $r = 0;
252 
253  sscanf($coord, '%[A-Z]%d', $c, $r);
254  if ($r != $row) {
255  continue;
256  }
257  $columnList[] = Coordinate::columnIndexFromString($c);
258  }
259 
260  return Coordinate::stringFromColumnIndex(max($columnList));
261  }
getCoordinates()
Get a list of all cell coordinates currently held in the collection.
Definition: Cells.php:140
getHighestRowAndColumn()
Get highest worksheet column and highest row that have cell records.
Definition: Cells.php:169
$r
Definition: example_031.php:79
$row
static columnIndexFromString($pString)
Column index from string.
Definition: Coordinate.php:265
static stringFromColumnIndex($columnIndex)
String from column index.
Definition: Coordinate.php:313
+ Here is the call graph for this function:

◆ getHighestRow()

PhpOffice\PhpSpreadsheet\Collection\Cells::getHighestRow (   $column = null)

Get highest worksheet row.

Parameters
string$columnReturn the highest row for the specified column, or the highest row of any column if no column letter is passed
Returns
int Highest row number

Definition at line 271 of file Cells.php.

References $c, $r, PhpOffice\PhpSpreadsheet\Collection\Cells\getCoordinates(), and PhpOffice\PhpSpreadsheet\Collection\Cells\getHighestRowAndColumn().

272  {
273  if ($column === null) {
274  $colRow = $this->getHighestRowAndColumn();
275 
276  return $colRow['row'];
277  }
278 
279  $rowList = [0];
280  foreach ($this->getCoordinates() as $coord) {
281  $c = '';
282  $r = 0;
283 
284  sscanf($coord, '%[A-Z]%d', $c, $r);
285  if ($c != $column) {
286  continue;
287  }
288  $rowList[] = $r;
289  }
290 
291  return max($rowList);
292  }
getCoordinates()
Get a list of all cell coordinates currently held in the collection.
Definition: Cells.php:140
getHighestRowAndColumn()
Get highest worksheet column and highest row that have cell records.
Definition: Cells.php:169
$r
Definition: example_031.php:79
+ Here is the call graph for this function:

◆ getHighestRowAndColumn()

PhpOffice\PhpSpreadsheet\Collection\Cells::getHighestRowAndColumn ( )

Get highest worksheet column and highest row that have cell records.

Returns
array Highest column name and highest row number

Definition at line 169 of file Cells.php.

References $c, $r, $row, and PhpOffice\PhpSpreadsheet\Collection\Cells\getCoordinates().

Referenced by PhpOffice\PhpSpreadsheet\Collection\Cells\getHighestColumn(), and PhpOffice\PhpSpreadsheet\Collection\Cells\getHighestRow().

170  {
171  // Lookup highest column and highest row
172  $col = ['A' => '1A'];
173  $row = [1];
174  foreach ($this->getCoordinates() as $coord) {
175  $c = '';
176  $r = 0;
177  sscanf($coord, '%[A-Z]%d', $c, $r);
178  $row[$r] = $r;
179  $col[$c] = strlen($c) . $c;
180  }
181 
182  // Determine highest column and row
183  $highestRow = max($row);
184  $highestColumn = substr(max($col), 1);
185 
186  return [
187  'row' => $highestRow,
188  'column' => $highestColumn,
189  ];
190  }
getCoordinates()
Get a list of all cell coordinates currently held in the collection.
Definition: Cells.php:140
$r
Definition: example_031.php:79
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getParent()

PhpOffice\PhpSpreadsheet\Collection\Cells::getParent ( )

Return the parent worksheet for this cell collection.

Returns
Worksheet

Definition at line 81 of file Cells.php.

References PhpOffice\PhpSpreadsheet\Collection\Cells\$parent.

◆ getSortedCoordinates()

PhpOffice\PhpSpreadsheet\Collection\Cells::getSortedCoordinates ( )

Get a sorted list of all cell coordinates currently held in the collection by row and column.

Returns
string[]

Definition at line 150 of file Cells.php.

References $row, and PhpOffice\PhpSpreadsheet\Collection\Cells\getCoordinates().

151  {
152  $sortKeys = [];
153  foreach ($this->getCoordinates() as $coord) {
154  $column = '';
155  $row = 0;
156  sscanf($coord, '%[A-Z]%d', $column, $row);
157  $sortKeys[sprintf('%09d%3s', $row, $column)] = $coord;
158  }
159  ksort($sortKeys);
160 
161  return array_values($sortKeys);
162  }
getCoordinates()
Get a list of all cell coordinates currently held in the collection.
Definition: Cells.php:140
$row
+ Here is the call graph for this function:

◆ getUniqueID()

PhpOffice\PhpSpreadsheet\Collection\Cells::getUniqueID ( )
private

Generate a unique ID for cache referencing.

Returns
string Unique Reference

Definition at line 299 of file Cells.php.

Referenced by PhpOffice\PhpSpreadsheet\Collection\Cells\__construct().

300  {
301  return uniqid('phpspreadsheet.', true) . '.';
302  }
+ Here is the caller graph for this function:

◆ has()

PhpOffice\PhpSpreadsheet\Collection\Cells::has (   $pCoord)

Whether the collection holds a cell for the given coordinate.

Parameters
string$pCoordCoordinate of the cell to check
Returns
bool

Definition at line 93 of file Cells.php.

Referenced by PhpOffice\PhpSpreadsheet\Collection\Cells\get().

94  {
95  if ($pCoord === $this->currentCoordinate) {
96  return true;
97  }
98 
99  // Check if the requested entry exists in the index
100  return isset($this->index[$pCoord]);
101  }
+ Here is the caller graph for this function:

◆ removeColumn()

PhpOffice\PhpSpreadsheet\Collection\Cells::removeColumn (   $column)

Remove a column, deleting all cells in that column.

Parameters
string$columnColumn ID to remove

Definition at line 367 of file Cells.php.

References $c, $r, and PhpOffice\PhpSpreadsheet\Collection\Cells\getCoordinates().

367  : void
368  {
369  foreach ($this->getCoordinates() as $coord) {
370  $c = '';
371  $r = 0;
372 
373  sscanf($coord, '%[A-Z]%d', $c, $r);
374  if ($c == $column) {
375  $this->delete($coord);
376  }
377  }
378  }
getCoordinates()
Get a list of all cell coordinates currently held in the collection.
Definition: Cells.php:140
$r
Definition: example_031.php:79
+ Here is the call graph for this function:

◆ removeRow()

PhpOffice\PhpSpreadsheet\Collection\Cells::removeRow (   $row)

Remove a row, deleting all cells in that row.

Parameters
string$rowRow number to remove

Definition at line 349 of file Cells.php.

References $c, $r, $row, and PhpOffice\PhpSpreadsheet\Collection\Cells\getCoordinates().

349  : void
350  {
351  foreach ($this->getCoordinates() as $coord) {
352  $c = '';
353  $r = 0;
354 
355  sscanf($coord, '%[A-Z]%d', $c, $r);
356  if ($r == $row) {
357  $this->delete($coord);
358  }
359  }
360  }
getCoordinates()
Get a list of all cell coordinates currently held in the collection.
Definition: Cells.php:140
$r
Definition: example_031.php:79
$row
+ Here is the call graph for this function:

◆ storeCurrentCell()

PhpOffice\PhpSpreadsheet\Collection\Cells::storeCurrentCell ( )
private

Store cell data in cache for the current cell object if it's "dirty", and the 'nullify' the current cell object.

Definition at line 384 of file Cells.php.

References PhpOffice\PhpSpreadsheet\Collection\Cells\__destruct().

Referenced by PhpOffice\PhpSpreadsheet\Collection\Cells\add(), PhpOffice\PhpSpreadsheet\Collection\Cells\cloneCellCollection(), and PhpOffice\PhpSpreadsheet\Collection\Cells\get().

384  : void
385  {
386  if ($this->currentCellIsDirty && !empty($this->currentCoordinate)) {
387  $this->currentCell->detach();
388 
389  $stored = $this->cache->set($this->cachePrefix . $this->currentCoordinate, $this->currentCell);
390  if (!$stored) {
391  $this->__destruct();
392 
393  throw new PhpSpreadsheetException("Failed to store cell {$this->currentCoordinate} in cache");
394  }
395  $this->currentCellIsDirty = false;
396  }
397 
398  $this->currentCoordinate = null;
399  $this->currentCell = null;
400  }
__destruct()
Destroy this cell collection.
Definition: Cells.php:482
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unsetWorksheetCells()

PhpOffice\PhpSpreadsheet\Collection\Cells::unsetWorksheetCells ( )

Clear the cell collection and disconnect from our parent.

Definition at line 462 of file Cells.php.

References PhpOffice\PhpSpreadsheet\Collection\Cells\__destruct().

462  : void
463  {
464  if ($this->currentCell !== null) {
465  $this->currentCell->detach();
466  $this->currentCell = null;
467  $this->currentCoordinate = null;
468  }
469 
470  // Flush the cache
471  $this->__destruct();
472 
473  $this->index = [];
474 
475  // detach ourself from the worksheet, so that it can then delete this object successfully
476  $this->parent = null;
477  }
__destruct()
Destroy this cell collection.
Definition: Cells.php:482
+ Here is the call graph for this function:

◆ update()

PhpOffice\PhpSpreadsheet\Collection\Cells::update ( Cell  $cell)

Add or update a cell in the collection.

Parameters
Cell$cellCell to update
Returns
Cell

Definition at line 110 of file Cells.php.

References PhpOffice\PhpSpreadsheet\Collection\Cells\add(), and PhpOffice\PhpSpreadsheet\Cell\Cell\getCoordinate().

111  {
112  return $this->add($cell->getCoordinate(), $cell);
113  }
add($pCoord, Cell $cell)
Add or update a cell identified by its coordinate into the collection.
Definition: Cells.php:410
+ Here is the call graph for this function:

Field Documentation

◆ $cache

PhpOffice\PhpSpreadsheet\Collection\Cells::$cache
private

Definition at line 17 of file Cells.php.

Referenced by PhpOffice\PhpSpreadsheet\Collection\Cells\__construct().

◆ $cachePrefix

PhpOffice\PhpSpreadsheet\Collection\Cells::$cachePrefix
private

Definition at line 59 of file Cells.php.

◆ $currentCell

PhpOffice\PhpSpreadsheet\Collection\Cells::$currentCell
private

Definition at line 31 of file Cells.php.

Referenced by PhpOffice\PhpSpreadsheet\Collection\Cells\get().

◆ $currentCellIsDirty

PhpOffice\PhpSpreadsheet\Collection\Cells::$currentCellIsDirty = false
private

Definition at line 45 of file Cells.php.

◆ $currentCoordinate

PhpOffice\PhpSpreadsheet\Collection\Cells::$currentCoordinate
private

◆ $index

PhpOffice\PhpSpreadsheet\Collection\Cells::$index = []
private

Definition at line 52 of file Cells.php.

◆ $parent


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