visualizer
/
vendor
/
phpoffice
/
phpexcel
/
Classes
/
PHPExcel
/
Worksheet
/
ColumnCellIterator.php
ColumnCellIterator.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.0.3, at vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet/ColumnCellIterator.php
| 1 | <?php |
| 2 | /** |
| 3 | * PHPExcel |
| 4 | * |
| 5 | * Copyright (c) 2006 - 2014 PHPExcel |
| 6 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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 |
| 20 | * |
| 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## |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | /** |
| 30 | * PHPExcel_Worksheet_ColumnCellIterator |
| 31 | * |
| 32 | * Used to iterate columns in a PHPExcel_Worksheet |
| 33 | * |
| 34 | * @category PHPExcel |
| 35 | * @package PHPExcel_Worksheet |
| 36 | * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) |
| 37 | */ |
| 38 | class PHPExcel_Worksheet_ColumnCellIterator extends PHPExcel_Worksheet_CellIterator implements Iterator |
| 39 | { |
| 40 | /** |
| 41 | * Column index |
| 42 | * |
| 43 | * @var string |
| 44 | */ |
| 45 | protected $_columnIndex; |
| 46 | |
| 47 | /** |
| 48 | * Start position |
| 49 | * |
| 50 | * @var int |
| 51 | */ |
| 52 | protected $_startRow = 1; |
| 53 | |
| 54 | /** |
| 55 | * End position |
| 56 | * |
| 57 | * @var int |
| 58 | */ |
| 59 | protected $_endRow = 1; |
| 60 | |
| 61 | /** |
| 62 | * Create a new row iterator |
| 63 | * |
| 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 |
| 68 | */ |
| 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 | |
| 77 | /** |
| 78 | * Destructor |
| 79 | */ |
| 80 | public function __destruct() { |
| 81 | unset($this->_subject); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * (Re)Set the start row and the current row pointer |
| 86 | * |
| 87 | * @param integer $startRow The row number at which to start iterating |
| 88 | * @return PHPExcel_Worksheet_ColumnCellIterator |
| 89 | * @throws PHPExcel_Exception |
| 90 | */ |
| 91 | public function resetStart($startRow = 1) { |
| 92 | $this->_startRow = $startRow; |
| 93 | $this->adjustForExistingOnlyRange(); |
| 94 | $this->seek($startRow); |
| 95 | |
| 96 | return $this; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * (Re)Set the end row |
| 101 | * |
| 102 | * @param integer $endRow The row number at which to stop iterating |
| 103 | * @return PHPExcel_Worksheet_ColumnCellIterator |
| 104 | * @throws PHPExcel_Exception |
| 105 | */ |
| 106 | public function resetEnd($endRow = null) { |
| 107 | $this->_endRow = ($endRow) ? $endRow : $this->_subject->getHighestRow(); |
| 108 | $this->adjustForExistingOnlyRange(); |
| 109 | |
| 110 | return $this; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Set the row pointer to the selected row |
| 115 | * |
| 116 | * @param integer $row The row number to set the current pointer at |
| 117 | * @return PHPExcel_Worksheet_ColumnCellIterator |
| 118 | * @throws PHPExcel_Exception |
| 119 | */ |
| 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 | |
| 131 | /** |
| 132 | * Rewind the iterator to the starting row |
| 133 | */ |
| 134 | public function rewind() { |
| 135 | $this->_position = $this->_startRow; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Return the current cell in this worksheet column |
| 140 | * |
| 141 | * @return PHPExcel_Worksheet_Row |
| 142 | */ |
| 143 | public function current() { |
| 144 | return $this->_subject->getCellByColumnAndRow($this->_columnIndex, $this->_position); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Return the current iterator key |
| 149 | * |
| 150 | * @return int |
| 151 | */ |
| 152 | public function key() { |
| 153 | return $this->_position; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Set the iterator to its next value |
| 158 | */ |
| 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)); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Set the iterator to its previous value |
| 169 | */ |
| 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 { |
| 176 | --$this->_position; |
| 177 | } while (($this->_onlyExistingCells) && |
| 178 | (!$this->_subject->cellExistsByColumnAndRow($this->_columnIndex, $this->_position)) && |
| 179 | ($this->_position >= $this->_startRow)); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Indicate if more rows exist in the worksheet range of rows that we're iterating |
| 184 | * |
| 185 | * @return boolean |
| 186 | */ |
| 187 | public function valid() { |
| 188 | return $this->_position <= $this->_endRow; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Validate start/end values for "IterateOnlyExistingCells" mode, and adjust if necessary |
| 193 | * |
| 194 | * @throws PHPExcel_Exception |
| 195 | */ |
| 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; |
| 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)) { |
| 207 | --$this->_endRow; |
| 208 | } |
| 209 | if ($this->_endRow < $this->_startRow) { |
| 210 | throw new PHPExcel_Exception('No cells exist within the specified range'); |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | } |
| 216 |