_subject = $subject; $this->_rowIndex = $rowIndex; } /** * Destructor */ public function __destruct() { unset($this->_subject); } /** * Rewind iterator */ public function rewind() { $this->_position = 0; } /** * Current PHPExcel_Cell * * @return PHPExcel_Cell */ public function current() { return $this->_subject->getCellByColumnAndRow($this->_position, $this->_rowIndex); } /** * Current key * * @return int */ public function key() { return $this->_position; } /** * Next value */ public function next() { ++$this->_position; } /** * More PHPExcel_Cell instances available? * * @return boolean */ public function valid() { // columnIndexFromString() returns an index based at one, // treat it as a count when comparing it to the base zero // position. $columnCount = PHPExcel_Cell::columnIndexFromString($this->_subject->getHighestColumn()); if ($this->_onlyExistingCells) { // If we aren't looking at an existing cell, either // because the first column doesn't exist or next() has // been called onto a nonexistent cell, then loop until we // find one, or pass the last column. while ($this->_position < $columnCount && !$this->_subject->cellExistsByColumnAndRow($this->_position, $this->_rowIndex)) { ++$this->_position; } } return $this->_position < $columnCount; } /** * Get loop only existing cells * * @return boolean */ public function getIterateOnlyExistingCells() { return $this->_onlyExistingCells; } /** * Set loop only existing cells * * @return boolean */ public function setIterateOnlyExistingCells($value = true) { $this->_onlyExistingCells = $value; } }