123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?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;
- $this->_startColumn = $startColumnIndex;
- $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;
- }
- }
|