Updated gui for user facility settings (#1327)
[openemr.git] / vendor / phpoffice / phpexcel / Classes / PHPExcel / Worksheet / ColumnCellIterator.php
bloba9ef49f00d71b335b161f520c72cec609150a6d2
1 <?php
2 /**
3 * PHPExcel
5 * Copyright (c) 2006 - 2014 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
21 * @category PHPExcel
22 * @package PHPExcel_Worksheet
23 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version ##VERSION##, ##DATE##
29 /**
30 * PHPExcel_Worksheet_ColumnCellIterator
32 * Used to iterate columns in a PHPExcel_Worksheet
34 * @category PHPExcel
35 * @package PHPExcel_Worksheet
36 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
38 class PHPExcel_Worksheet_ColumnCellIterator extends PHPExcel_Worksheet_CellIterator implements Iterator
40 /**
41 * Column index
43 * @var string
45 protected $_columnIndex;
47 /**
48 * Start position
50 * @var int
52 protected $_startRow = 1;
54 /**
55 * End position
57 * @var int
59 protected $_endRow = 1;
61 /**
62 * Create a new row iterator
64 * @param PHPExcel_Worksheet $subject The worksheet to iterate over
65 * @param string $columnIndex The column that we want to iterate
66 * @param integer $startRow The row number at which to start iterating
67 * @param integer $endRow Optionally, the row number at which to stop iterating
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);
77 /**
78 * Destructor
80 public function __destruct() {
81 unset($this->_subject);
84 /**
85 * (Re)Set the start row and the current row pointer
87 * @param integer $startRow The row number at which to start iterating
88 * @return PHPExcel_Worksheet_ColumnCellIterator
89 * @throws PHPExcel_Exception
91 public function resetStart($startRow = 1) {
92 $this->_startRow = $startRow;
93 $this->adjustForExistingOnlyRange();
94 $this->seek($startRow);
96 return $this;
99 /**
100 * (Re)Set the end row
102 * @param integer $endRow The row number at which to stop iterating
103 * @return PHPExcel_Worksheet_ColumnCellIterator
104 * @throws PHPExcel_Exception
106 public function resetEnd($endRow = null) {
107 $this->_endRow = ($endRow) ? $endRow : $this->_subject->getHighestRow();
108 $this->adjustForExistingOnlyRange();
110 return $this;
114 * Set the row pointer to the selected row
116 * @param integer $row The row number to set the current pointer at
117 * @return PHPExcel_Worksheet_ColumnCellIterator
118 * @throws PHPExcel_Exception
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');
126 $this->_position = $row;
128 return $this;
132 * Rewind the iterator to the starting row
134 public function rewind() {
135 $this->_position = $this->_startRow;
139 * Return the current cell in this worksheet column
141 * @return PHPExcel_Worksheet_Row
143 public function current() {
144 return $this->_subject->getCellByColumnAndRow($this->_columnIndex, $this->_position);
148 * Return the current iterator key
150 * @return int
152 public function key() {
153 return $this->_position;
157 * Set the iterator to its next value
159 public function next() {
160 do {
161 ++$this->_position;
162 } while (($this->_onlyExistingCells) &&
163 (!$this->_subject->cellExistsByColumnAndRow($this->_columnIndex, $this->_position)) &&
164 ($this->_position <= $this->_endRow));
168 * Set the iterator to its previous value
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})");
175 do {
176 --$this->_position;
177 } while (($this->_onlyExistingCells) &&
178 (!$this->_subject->cellExistsByColumnAndRow($this->_columnIndex, $this->_position)) &&
179 ($this->_position >= $this->_startRow));
183 * Indicate if more rows exist in the worksheet range of rows that we're iterating
185 * @return boolean
187 public function valid() {
188 return $this->_position <= $this->_endRow;
192 * Validate start/end values for "IterateOnlyExistingCells" mode, and adjust if necessary
194 * @throws PHPExcel_Exception
196 protected function adjustForExistingOnlyRange() {
197 if ($this->_onlyExistingCells) {
198 while ((!$this->_subject->cellExistsByColumnAndRow($this->_columnIndex, $this->_startRow)) &&
199 ($this->_startRow <= $this->_endRow)) {
200 ++$this->_startRow;
202 if ($this->_startRow > $this->_endRow) {
203 throw new PHPExcel_Exception('No cells exist within the specified range');
205 while ((!$this->_subject->cellExistsByColumnAndRow($this->_columnIndex, $this->_endRow)) &&
206 ($this->_endRow >= $this->_startRow)) {
207 --$this->_endRow;
209 if ($this->_endRow < $this->_startRow) {
210 throw new PHPExcel_Exception('No cells exist within the specified range');