5
* Copyright (c) 2006 - 2009 PHPExcel
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
* @package PHPExcel_Worksheet
23
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
24
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
* @version 1.7.0, 2009-08-10
29
/** PHPExcel root directory */
30
if (!defined('PHPEXCEL_ROOT')) {
34
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
38
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
40
/** PHPExcel_Worksheet */
41
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
44
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
48
* PHPExcel_Worksheet_CellIterator
50
* Used to iterate rows in a PHPExcel_Worksheet
53
* @package PHPExcel_Worksheet
54
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
56
class PHPExcel_Worksheet_CellIterator extends IteratorIterator
59
* PHPExcel_Worksheet to iterate
61
* @var PHPExcel_Worksheet
73
* Current iterator position
77
private $_position = 0;
80
* Loop only existing cells
84
private $_onlyExistingCells = true;
87
* Create a new cell iterator
89
* @param PHPExcel_Worksheet $subject
90
* @param int $rowIndex
92
public function __construct(PHPExcel_Worksheet $subject = null, $rowIndex = 1) {
93
// Set subject and row index
94
$this->_subject = $subject;
95
$this->_rowIndex = $rowIndex;
101
public function __destruct() {
102
unset($this->_subject);
108
public function rewind() {
109
$this->_position = 0;
113
* Current PHPExcel_Cell
115
* @return PHPExcel_Cell
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()) {
125
if ($this->_subject->cellExistsByColumnAndRow($this->_position, $this->_rowIndex)) {
126
return $this->_subject->getCellByColumnAndRow($this->_position, $this->_rowIndex);
139
public function key() {
140
return $this->_position;
146
public function next() {
151
* More PHPExcel_Cell instances available?
155
public function valid() {
156
return $this->_position < PHPExcel_Cell::columnIndexFromString( $this->_subject->getHighestColumn() );
160
* Get loop only existing cells
164
public function getIterateOnlyExistingCells() {
165
return $this->_onlyExistingCells;
169
* Set loop only existing cells
173
public function setIterateOnlyExistingCells($value = true) {
174
$this->_onlyExistingCells = $value;