/** * Run PHPExcel garabage collector. * * @return Worksheet */ public function garbageCollect() { // Flush cache $this->cellCollection->getCacheData('A1'); // Build a reference table from images // $imageCoordinates = array(); // $iterator = $this->getDrawingCollection()->getIterator(); // while ($iterator->valid()) { // $imageCoordinates[$iterator->current()->getCoordinates()] = true; // // $iterator->next(); // } // // Lookup highest column and highest row if cells are cleaned $colRow = $this->cellCollection->getHighestRowAndColumn(); $highestRow = $colRow['row']; $highestColumn = Cell::columnIndexFromString($colRow['column']); // Loop through column dimensions foreach ($this->columnDimensions as $dimension) { $highestColumn = max($highestColumn, Cell::columnIndexFromString($dimension->getColumnIndex())); } // Loop through row dimensions foreach ($this->rowDimensions as $dimension) { $highestRow = max($highestRow, $dimension->getRowIndex()); } // Cache values if ($highestColumn < 0) { $this->cachedHighestColumn = 'A'; } else { $this->cachedHighestColumn = Cell::stringFromColumnIndex(--$highestColumn); } $this->cachedHighestRow = $highestRow; // Return return $this; }
/** * Run PHPExcel garabage collector. * * @return Worksheet */ public function garbageCollect() { // Build a reference table from images $imageCoordinates = array(); $iterator = $this->getDrawingCollection()->getIterator(); while ($iterator->valid()) { $imageCoordinates[$iterator->current()->getCoordinates()] = true; $iterator->next(); } // Lookup highest column and highest row if cells are cleaned $highestColumn = -1; $highestRow = 1; // Find cells that can be cleaned foreach ($this->_cellCollection->getCellList() as $coordinate) { preg_match('/^(\\w+)(\\d+)$/U', $coordinate, $matches); list(, $col, $row) = $matches; $column = Cell::columnIndexFromString($col); // Determine highest column and row if ($highestColumn < $column) { $highestColumn = $column; } if ($row > $highestRow) { $highestRow = $row; } } // Loop through column dimensions foreach ($this->_columnDimensions as $dimension) { if ($highestColumn < Cell::columnIndexFromString($dimension->getColumnIndex())) { $highestColumn = Cell::columnIndexFromString($dimension->getColumnIndex()); } } // Loop through row dimensions foreach ($this->_rowDimensions as $dimension) { if ($highestRow < $dimension->getRowIndex()) { $highestRow = $dimension->getRowIndex(); } } // Cache values if ($highestColumn < 0) { $this->_cachedHighestColumn = 'A'; } else { $this->_cachedHighestColumn = Cell::stringFromColumnIndex(--$highestColumn); } $this->_cachedHighestRow = $highestRow; // Return return $this; }