ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
RowCellIterator.php
Go to the documentation of this file.
1 <?php
39 {
45  protected $_rowIndex;
46 
52  protected $_startColumn = 0;
53 
59  protected $_endColumn = 0;
60 
69  public function __construct(PHPExcel_Worksheet $subject = null, $rowIndex = 1, $startColumn = 'A', $endColumn = null) {
70  // Set subject and row index
71  $this->_subject = $subject;
72  $this->_rowIndex = $rowIndex;
73  $this->resetEnd($endColumn);
74  $this->resetStart($startColumn);
75  }
76 
80  public function __destruct() {
81  unset($this->_subject);
82  }
83 
91  public function resetStart($startColumn = 'A') {
92  $startColumnIndex = PHPExcel_Cell::columnIndexFromString($startColumn) - 1;
93  $this->_startColumn = $startColumnIndex;
95  $this->seek(PHPExcel_Cell::stringFromColumnIndex($this->_startColumn));
96 
97  return $this;
98  }
99 
107  public function resetEnd($endColumn = null) {
108  $endColumn = ($endColumn) ? $endColumn : $this->_subject->getHighestColumn();
109  $this->_endColumn = PHPExcel_Cell::columnIndexFromString($endColumn) - 1;
111 
112  return $this;
113  }
114 
122  public function seek($column = 'A') {
124  if (($column < $this->_startColumn) || ($column > $this->_endColumn)) {
125  throw new PHPExcel_Exception("Column $column is out of range ({$this->_startColumn} - {$this->_endColumn})");
126  } elseif ($this->_onlyExistingCells && !($this->_subject->cellExistsByColumnAndRow($column, $this->_rowIndex))) {
127  throw new PHPExcel_Exception('In "IterateOnlyExistingCells" mode and Cell does not exist');
128  }
129  $this->_position = $column;
130 
131  return $this;
132  }
133 
137  public function rewind() {
138  $this->_position = $this->_startColumn;
139  }
140 
146  public function current() {
147  return $this->_subject->getCellByColumnAndRow($this->_position, $this->_rowIndex);
148  }
149 
155  public function key() {
156  return PHPExcel_Cell::stringFromColumnIndex($this->_position);
157  }
158 
162  public function next() {
163  do {
165  } while (($this->_onlyExistingCells) &&
166  (!$this->_subject->cellExistsByColumnAndRow($this->_position, $this->_rowIndex)) &&
167  ($this->_position <= $this->_endColumn));
168  }
169 
175  public function prev() {
176  if ($this->_position <= $this->_startColumn) {
177  throw new PHPExcel_Exception(
178  "Column is already at the beginning of range (" .
179  PHPExcel_Cell::stringFromColumnIndex($this->_endColumn) . " - " .
180  PHPExcel_Cell::stringFromColumnIndex($this->_endColumn) . ")"
181  );
182  }
183 
184  do {
186  } while (($this->_onlyExistingCells) &&
187  (!$this->_subject->cellExistsByColumnAndRow($this->_position, $this->_rowIndex)) &&
188  ($this->_position >= $this->_startColumn));
189  }
190 
196  public function valid() {
197  return $this->_position <= $this->_endColumn;
198  }
199 
205  protected function adjustForExistingOnlyRange() {
206  if ($this->_onlyExistingCells) {
207  while ((!$this->_subject->cellExistsByColumnAndRow($this->_startColumn, $this->_rowIndex)) &&
208  ($this->_startColumn <= $this->_endColumn)) {
210  }
211  if ($this->_startColumn > $this->_endColumn) {
212  throw new PHPExcel_Exception('No cells exist within the specified range');
213  }
214  while ((!$this->_subject->cellExistsByColumnAndRow($this->_endColumn, $this->_rowIndex)) &&
215  ($this->_endColumn >= $this->_startColumn)) {
217  }
218  if ($this->_endColumn < $this->_startColumn) {
219  throw new PHPExcel_Exception('No cells exist within the specified range');
220  }
221  }
222  }
223 
224 }
seek($column='A')
Set the column pointer to the selected column.
key()
Return the current iterator key.
adjustForExistingOnlyRange()
Validate start/end values for "IterateOnlyExistingCells" mode, and adjust if necessary.
prev()
Set the iterator to its previous value.
current()
Return the current cell in this worksheet row.
$column
Definition: 39dropdown.php:62
valid()
Indicate if more columns exist in the worksheet range of columns that we&#39;re iterating.
__construct(PHPExcel_Worksheet $subject=null, $rowIndex=1, $startColumn='A', $endColumn=null)
Create a new column iterator.
static columnIndexFromString($pString='A')
Column index from string.
Definition: Cell.php:782
resetEnd($endColumn=null)
(Re)Set the end column
static stringFromColumnIndex($pColumnIndex=0)
String from columnindex.
Definition: Cell.php:825
next()
Set the iterator to its next value.
rewind()
Rewind the iterator to the starting column.
resetStart($startColumn='A')
(Re)Set the start column and the current column pointer