ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ColumnCellIterator.php
Go to the documentation of this file.
1<?php
39{
45 protected $_columnIndex;
46
52 protected $_startRow = 1;
53
59 protected $_endRow = 1;
60
69 public function __construct(PHPExcel_Worksheet $subject = null, $columnIndex, $startRow = 1, $endRow = null) {
70 // Set subject
71 $this->_subject = $subject;
72 $this->_columnIndex = PHPExcel_Cell::columnIndexFromString($columnIndex) - 1;
73 $this->resetEnd($endRow);
74 $this->resetStart($startRow);
75 }
76
80 public function __destruct() {
81 unset($this->_subject);
82 }
83
91 public function resetStart($startRow = 1) {
92 $this->_startRow = $startRow;
94 $this->seek($startRow);
95
96 return $this;
97 }
98
106 public function resetEnd($endRow = null) {
107 $this->_endRow = ($endRow) ? $endRow : $this->_subject->getHighestRow();
109
110 return $this;
111 }
112
120 public function seek($row = 1) {
121 if (($row < $this->_startRow) || ($row > $this->_endRow)) {
122 throw new PHPExcel_Exception("Row $row is out of range ({$this->_startRow} - {$this->_endRow})");
123 } elseif ($this->_onlyExistingCells && !($this->_subject->cellExistsByColumnAndRow($this->_columnIndex, $row))) {
124 throw new PHPExcel_Exception('In "IterateOnlyExistingCells" mode and Cell does not exist');
125 }
126 $this->_position = $row;
127
128 return $this;
129 }
130
134 public function rewind() {
135 $this->_position = $this->_startRow;
136 }
137
143 public function current() {
144 return $this->_subject->getCellByColumnAndRow($this->_columnIndex, $this->_position);
145 }
146
152 public function key() {
153 return $this->_position;
154 }
155
159 public function next() {
160 do {
162 } while (($this->_onlyExistingCells) &&
163 (!$this->_subject->cellExistsByColumnAndRow($this->_columnIndex, $this->_position)) &&
164 ($this->_position <= $this->_endRow));
165 }
166
170 public function prev() {
171 if ($this->_position <= $this->_startRow) {
172 throw new PHPExcel_Exception("Row is already at the beginning of range ({$this->_startRow} - {$this->_endRow})");
173 }
174
175 do {
177 } while (($this->_onlyExistingCells) &&
178 (!$this->_subject->cellExistsByColumnAndRow($this->_columnIndex, $this->_position)) &&
179 ($this->_position >= $this->_startRow));
180 }
181
187 public function valid() {
188 return $this->_position <= $this->_endRow;
189 }
190
196 protected function adjustForExistingOnlyRange() {
197 if ($this->_onlyExistingCells) {
198 while ((!$this->_subject->cellExistsByColumnAndRow($this->_columnIndex, $this->_startRow)) &&
199 ($this->_startRow <= $this->_endRow)) {
201 }
202 if ($this->_startRow > $this->_endRow) {
203 throw new PHPExcel_Exception('No cells exist within the specified range');
204 }
205 while ((!$this->_subject->cellExistsByColumnAndRow($this->_columnIndex, $this->_endRow)) &&
206 ($this->_endRow >= $this->_startRow)) {
208 }
209 if ($this->_endRow < $this->_startRow) {
210 throw new PHPExcel_Exception('No cells exist within the specified range');
211 }
212 }
213 }
214
215}
An exception for terminatinating execution or to throw for unit testing.
static columnIndexFromString($pString='A')
Column index from string.
Definition: Cell.php:782
valid()
Indicate if more rows exist in the worksheet range of rows that we're iterating.
__construct(PHPExcel_Worksheet $subject=null, $columnIndex, $startRow=1, $endRow=null)
current()
Return the current cell in this worksheet column.
key()
Return the current iterator key.
prev()
Set the iterator to its previous value.
next()
Set the iterator to its next value.
rewind()
Rewind the iterator to the starting row.