123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- class PHPExcel_Worksheet_RowCellIterator extends PHPExcel_Worksheet_CellIterator implements Iterator
- {
-
- protected $_rowIndex;
-
- protected $_startColumn = 0;
-
- protected $_endColumn = 0;
-
- public function __construct(PHPExcel_Worksheet $subject = null, $rowIndex = 1, $startColumn = 'A', $endColumn = null) {
-
- $this->_subject = $subject;
- $this->_rowIndex = $rowIndex;
- $this->resetEnd($endColumn);
- $this->resetStart($startColumn);
- }
-
- public function __destruct() {
- unset($this->_subject);
- }
-
- public function resetStart($startColumn = 'A') {
- $startColumnIndex = PHPExcel_Cell::columnIndexFromString($startColumn) - 1;
- $this->_startColumn = $startColumnIndex;
- $this->adjustForExistingOnlyRange();
- $this->seek(PHPExcel_Cell::stringFromColumnIndex($this->_startColumn));
- return $this;
- }
-
- public function resetEnd($endColumn = null) {
- $endColumn = ($endColumn) ? $endColumn : $this->_subject->getHighestColumn();
- $this->_endColumn = PHPExcel_Cell::columnIndexFromString($endColumn) - 1;
- $this->adjustForExistingOnlyRange();
- return $this;
- }
-
- public function seek($column = 'A') {
- $column = PHPExcel_Cell::columnIndexFromString($column) - 1;
- if (($column < $this->_startColumn) || ($column > $this->_endColumn)) {
- throw new PHPExcel_Exception("Column $column is out of range ({$this->_startColumn} - {$this->_endColumn})");
- } elseif ($this->_onlyExistingCells && !($this->_subject->cellExistsByColumnAndRow($column, $this->_rowIndex))) {
- throw new PHPExcel_Exception('In "IterateOnlyExistingCells" mode and Cell does not exist');
- }
- $this->_position = $column;
- return $this;
- }
-
- public function rewind() {
- $this->_position = $this->_startColumn;
- }
-
- public function current() {
- return $this->_subject->getCellByColumnAndRow($this->_position, $this->_rowIndex);
- }
-
- public function key() {
- return PHPExcel_Cell::stringFromColumnIndex($this->_position);
- }
-
- public function next() {
- do {
- ++$this->_position;
- } while (($this->_onlyExistingCells) &&
- (!$this->_subject->cellExistsByColumnAndRow($this->_position, $this->_rowIndex)) &&
- ($this->_position <= $this->_endColumn));
- }
-
- public function prev() {
- if ($this->_position <= $this->_startColumn) {
- throw new PHPExcel_Exception(
- "Column is already at the beginning of range (" .
- PHPExcel_Cell::stringFromColumnIndex($this->_endColumn) . " - " .
- PHPExcel_Cell::stringFromColumnIndex($this->_endColumn) . ")"
- );
- }
- do {
- --$this->_position;
- } while (($this->_onlyExistingCells) &&
- (!$this->_subject->cellExistsByColumnAndRow($this->_position, $this->_rowIndex)) &&
- ($this->_position >= $this->_startColumn));
- }
-
- public function valid() {
- return $this->_position <= $this->_endColumn;
- }
-
- protected function adjustForExistingOnlyRange() {
- if ($this->_onlyExistingCells) {
- while ((!$this->_subject->cellExistsByColumnAndRow($this->_startColumn, $this->_rowIndex)) &&
- ($this->_startColumn <= $this->_endColumn)) {
- ++$this->_startColumn;
- }
- if ($this->_startColumn > $this->_endColumn) {
- throw new PHPExcel_Exception('No cells exist within the specified range');
- }
- while ((!$this->_subject->cellExistsByColumnAndRow($this->_endColumn, $this->_rowIndex)) &&
- ($this->_endColumn >= $this->_startColumn)) {
- --$this->_endColumn;
- }
- if ($this->_endColumn < $this->_startColumn) {
- throw new PHPExcel_Exception('No cells exist within the specified range');
- }
- }
- }
- }
|