Esempio n. 1
0
 /**
  * Get collection of cells
  *
  * @param boolean $pSorted Also sort the cell collection?
  * @return Cell[]
  */
 public function getCellCollection($pSorted = true)
 {
     if ($pSorted) {
         // Re-order cell collection
         return $this->sortCellCollection();
     }
     if ($this->cellCollection !== null) {
         return $this->cellCollection->getCellList();
     }
     return array();
 }
Esempio n. 2
0
 /**
  * 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;
 }