123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- class PHPExcel_Worksheet_RowIterator implements Iterator
- {
-
- private $subject;
-
- private $position = 1;
-
- private $startRow = 1;
-
- private $endRow = 1;
-
- public function __construct(PHPExcel_Worksheet $subject, $startRow = 1, $endRow = null)
- {
-
- $this->subject = $subject;
- $this->resetEnd($endRow);
- $this->resetStart($startRow);
- }
-
- public function __destruct()
- {
- unset($this->subject);
- }
-
- public function resetStart($startRow = 1)
- {
- if ($startRow > $this->subject->getHighestRow()) {
- throw new PHPExcel_Exception("Start row ({$startRow}) is beyond highest row ({$this->subject->getHighestRow()})");
- }
- $this->startRow = $startRow;
- if ($this->endRow < $this->startRow) {
- $this->endRow = $this->startRow;
- }
- $this->seek($startRow);
- return $this;
- }
-
- public function resetEnd($endRow = null)
- {
- $this->endRow = ($endRow) ? $endRow : $this->subject->getHighestRow();
- return $this;
- }
-
- public function seek($row = 1)
- {
- if (($row < $this->startRow) || ($row > $this->endRow)) {
- throw new PHPExcel_Exception("Row $row is out of range ({$this->startRow} - {$this->endRow})");
- }
- $this->position = $row;
- return $this;
- }
-
- public function rewind()
- {
- $this->position = $this->startRow;
- }
-
- public function current()
- {
- return new PHPExcel_Worksheet_Row($this->subject, $this->position);
- }
-
- public function key()
- {
- return $this->position;
- }
-
- public function next()
- {
- ++$this->position;
- }
-
- public function prev()
- {
- if ($this->position <= $this->startRow) {
- throw new PHPExcel_Exception("Row is already at the beginning of range ({$this->startRow} - {$this->endRow})");
- }
- --$this->position;
- }
-
- public function valid()
- {
- return $this->position <= $this->endRow;
- }
- }
|