123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <?php
- class PHPExcel_Worksheet_ColumnIterator implements Iterator
- {
-
- private $subject;
-
- private $position = 0;
-
- private $startColumn = 0;
-
- private $endColumn = 0;
-
- public function __construct(PHPExcel_Worksheet $subject = null, $startColumn = 'A', $endColumn = null)
- {
-
- $this->subject = $subject;
- $this->resetEnd($endColumn);
- $this->resetStart($startColumn);
- }
-
- public function __destruct()
- {
- unset($this->subject);
- }
-
- public function resetStart($startColumn = 'A')
- {
- $startColumnIndex = PHPExcel_Cell::columnIndexFromString($startColumn) - 1;
- if ($startColumnIndex > PHPExcel_Cell::columnIndexFromString($this->subject->getHighestColumn()) - 1) {
- throw new PHPExcel_Exception("Start column ({$startColumn}) is beyond highest column ({$this->subject->getHighestColumn()})");
- }
- $this->startColumn = $startColumnIndex;
- if ($this->endColumn < $this->startColumn) {
- $this->endColumn = $this->startColumn;
- }
- $this->seek($startColumn);
- return $this;
- }
-
- public function resetEnd($endColumn = null)
- {
- $endColumn = ($endColumn) ? $endColumn : $this->subject->getHighestColumn();
- $this->endColumn = PHPExcel_Cell::columnIndexFromString($endColumn) - 1;
- 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})");
- }
- $this->position = $column;
- return $this;
- }
-
- public function rewind()
- {
- $this->position = $this->startColumn;
- }
-
- public function current()
- {
- return new PHPExcel_Worksheet_Column($this->subject, PHPExcel_Cell::stringFromColumnIndex($this->position));
- }
-
- public function key()
- {
- return PHPExcel_Cell::stringFromColumnIndex($this->position);
- }
-
- public function next()
- {
- ++$this->position;
- }
-
- 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) . ")"
- );
- }
- --$this->position;
- }
-
- public function valid()
- {
- return $this->position <= $this->endColumn;
- }
- }
|