ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
CellIterator.php
Go to the documentation of this file.
1 <?php
30 if (!defined('PHPEXCEL_ROOT')) {
34  define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35 }
36 
38 require_once PHPEXCEL_ROOT . 'PHPExcel.php';
39 
41 require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
42 
44 require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
45 
46 
57 {
63  private $_subject;
64 
70  private $_rowIndex;
71 
77  private $_position = 0;
78 
84  private $_onlyExistingCells = true;
85 
92  public function __construct(PHPExcel_Worksheet $subject = null, $rowIndex = 1) {
93  // Set subject and row index
94  $this->_subject = $subject;
95  $this->_rowIndex = $rowIndex;
96  }
97 
101  public function __destruct() {
102  unset($this->_subject);
103  }
104 
108  public function rewind() {
109  $this->_position = 0;
110  }
111 
117  public function current() {
118  $cellExists = $this->_subject->cellExistsByColumnAndRow($this->_position, $this->_rowIndex);
119  if ( ($this->_onlyExistingCells && $cellExists) || (!$this->_onlyExistingCells) ) {
120  return $this->_subject->getCellByColumnAndRow($this->_position, $this->_rowIndex);
121  } else if ($this->_onlyExistingCells && !$cellExists) {
122  // Loop untill we find one
123  while ($this->valid()) {
124  $this->next();
125  if ($this->_subject->cellExistsByColumnAndRow($this->_position, $this->_rowIndex)) {
126  return $this->_subject->getCellByColumnAndRow($this->_position, $this->_rowIndex);
127  }
128  }
129  }
130 
131  return null;
132  }
133 
139  public function key() {
140  return $this->_position;
141  }
142 
146  public function next() {
148  }
149 
155  public function valid() {
156  return $this->_position < PHPExcel_Cell::columnIndexFromString( $this->_subject->getHighestColumn() );
157  }
158 
164  public function getIterateOnlyExistingCells() {
166  }
167 
173  public function setIterateOnlyExistingCells($value = true) {
174  $this->_onlyExistingCells = $value;
175  }
176 }