93 public function has($pCoord)
95 if ($pCoord === $this->currentCoordinate) {
100 return isset($this->index[$pCoord]);
120 public function delete($pCoord):
void 122 if ($pCoord === $this->currentCoordinate && $this->currentCell !== null) {
123 $this->currentCell->detach();
124 $this->currentCoordinate = null;
125 $this->currentCell = null;
126 $this->currentCellIsDirty =
false;
129 unset($this->index[$pCoord]);
132 $this->cache->delete($this->cachePrefix . $pCoord);
142 return array_keys($this->index);
156 sscanf($coord,
'%[A-Z]%d', $column,
$row);
157 $sortKeys[sprintf(
'%09d%3s',
$row, $column)] = $coord;
161 return array_values($sortKeys);
172 $col = [
'A' =>
'1A'];
177 sscanf($coord,
'%[A-Z]%d',
$c,
$r);
179 $col[
$c] = strlen(
$c) .
$c;
183 $highestRow = max(
$row);
184 $highestColumn = substr(max($col), 1);
187 'row' => $highestRow,
188 'column' => $highestColumn,
212 sscanf($this->currentCoordinate,
'%[A-Z]%d', $column,
$row);
227 sscanf($this->currentCoordinate,
'%[A-Z]%d', $column,
$row);
245 return $colRow[
'column'];
253 sscanf($coord,
'%[A-Z]%d',
$c,
$r);
273 if ($column === null) {
276 return $colRow[
'row'];
284 sscanf($coord,
'%[A-Z]%d',
$c,
$r);
291 return max($rowList);
301 return uniqid(
'phpspreadsheet.',
true) .
'.';
314 $newCollection = clone $this;
316 $newCollection->parent =
$parent;
317 if (($newCollection->currentCell !== null) && (is_object($newCollection->currentCell))) {
318 $newCollection->currentCell->attach($this);
322 $oldKeys = $newCollection->getAllCacheKeys();
323 $oldValues = $newCollection->cache->getMultiple($oldKeys);
325 $oldCachePrefix = $newCollection->cachePrefix;
328 $newCollection->cachePrefix = $newCollection->getUniqueID();
329 foreach ($oldValues as $oldKey => $value) {
330 $newValues[str_replace($oldCachePrefix, $newCollection->cachePrefix, $oldKey)] = clone $value;
334 $stored = $newCollection->cache->setMultiple($newValues);
336 $newCollection->__destruct();
341 return $newCollection;
355 sscanf($coord,
'%[A-Z]%d',
$c,
$r);
357 $this->
delete($coord);
373 sscanf($coord,
'%[A-Z]%d',
$c,
$r);
375 $this->
delete($coord);
386 if ($this->currentCellIsDirty && !empty($this->currentCoordinate)) {
387 $this->currentCell->detach();
389 $stored = $this->cache->set($this->cachePrefix . $this->currentCoordinate, $this->currentCell);
395 $this->currentCellIsDirty =
false;
398 $this->currentCoordinate = null;
399 $this->currentCell = null;
412 if ($pCoord !== $this->currentCoordinate) {
415 $this->index[$pCoord] =
true;
417 $this->currentCoordinate = $pCoord;
418 $this->currentCell = $cell;
419 $this->currentCellIsDirty =
true;
431 public function get($pCoord)
433 if ($pCoord === $this->currentCoordinate) {
439 if (!$this->
has($pCoord)) {
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.");
450 $this->currentCoordinate = $pCoord;
451 $this->currentCell = $cell;
453 $this->currentCell->attach($this);
464 if ($this->currentCell !== null) {
465 $this->currentCell->detach();
466 $this->currentCell = null;
467 $this->currentCoordinate = null;
495 yield $this->cachePrefix . $coordinate;
getCoordinates()
Get a list of all cell coordinates currently held in the collection.
getHighestRow($column=null)
Get highest worksheet row.
getCurrentColumn()
Return the column coordinate of the currently active cell object.
getCoordinate()
Get cell coordinate.
getSortedCoordinates()
Get a sorted list of all cell coordinates currently held in the collection by row and column...
cloneCellCollection(Worksheet $parent)
Clone the cell collection.
getHighestRowAndColumn()
Get highest worksheet column and highest row that have cell records.
add($pCoord, Cell $cell)
Add or update a cell identified by its coordinate into the collection.
__construct(Worksheet $parent, CacheInterface $cache)
Initialise this new cell collection.
getCurrentCoordinate()
Return the cell coordinate of the currently active cell object.
getHighestColumn($row=null)
Get highest worksheet column.
update(Cell $cell)
Add or update a cell in the collection.
getParent()
Return the parent worksheet for this cell collection.
__destruct()
Destroy this cell collection.
removeColumn($column)
Remove a column, deleting all cells in that column.
getUniqueID()
Generate a unique ID for cache referencing.
removeRow($row)
Remove a row, deleting all cells in that row.
getAllCacheKeys()
Returns all known cache keys.
unsetWorksheetCells()
Clear the cell collection and disconnect from our parent.
storeCurrentCell()
Store cell data in cache for the current cell object if it's "dirty", and the 'nullify' the current c...
static columnIndexFromString($pString)
Column index from string.
static stringFromColumnIndex($columnIndex)
String from column index.
getCurrentRow()
Return the row coordinate of the currently active cell object.
has($pCoord)
Whether the collection holds a cell for the given coordinate.