[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * PHPExcel_Worksheet_RowIterator 5 * 6 * Copyright (c) 2006 - 2015 PHPExcel 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 * 22 * @category PHPExcel 23 * @package PHPExcel_Worksheet 24 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) 25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL 26 * @version ##VERSION##, ##DATE## 27 */ 28 class PHPExcel_Worksheet_RowIterator implements Iterator 29 { 30 /** 31 * PHPExcel_Worksheet to iterate 32 * 33 * @var PHPExcel_Worksheet 34 */ 35 private $subject; 36 37 /** 38 * Current iterator position 39 * 40 * @var int 41 */ 42 private $position = 1; 43 44 /** 45 * Start position 46 * 47 * @var int 48 */ 49 private $startRow = 1; 50 51 52 /** 53 * End position 54 * 55 * @var int 56 */ 57 private $endRow = 1; 58 59 60 /** 61 * Create a new row iterator 62 * 63 * @param PHPExcel_Worksheet $subject The worksheet to iterate over 64 * @param integer $startRow The row number at which to start iterating 65 * @param integer $endRow Optionally, the row number at which to stop iterating 66 */ 67 public function __construct(PHPExcel_Worksheet $subject = null, $startRow = 1, $endRow = null) 68 { 69 // Set subject 70 $this->subject = $subject; 71 $this->resetEnd($endRow); 72 $this->resetStart($startRow); 73 } 74 75 /** 76 * Destructor 77 */ 78 public function __destruct() 79 { 80 unset($this->subject); 81 } 82 83 /** 84 * (Re)Set the start row and the current row pointer 85 * 86 * @param integer $startRow The row number at which to start iterating 87 * @return PHPExcel_Worksheet_RowIterator 88 */ 89 public function resetStart($startRow = 1) 90 { 91 $this->startRow = $startRow; 92 $this->seek($startRow); 93 94 return $this; 95 } 96 97 /** 98 * (Re)Set the end row 99 * 100 * @param integer $endRow The row number at which to stop iterating 101 * @return PHPExcel_Worksheet_RowIterator 102 */ 103 public function resetEnd($endRow = null) 104 { 105 $this->endRow = ($endRow) ? $endRow : $this->subject->getHighestRow(); 106 107 return $this; 108 } 109 110 /** 111 * Set the row pointer to the selected row 112 * 113 * @param integer $row The row number to set the current pointer at 114 * @return PHPExcel_Worksheet_RowIterator 115 * @throws PHPExcel_Exception 116 */ 117 public function seek($row = 1) 118 { 119 if (($row < $this->startRow) || ($row > $this->endRow)) { 120 throw new PHPExcel_Exception("Row $row is out of range ({$this->startRow} - {$this->endRow})"); 121 } 122 $this->position = $row; 123 124 return $this; 125 } 126 127 /** 128 * Rewind the iterator to the starting row 129 */ 130 public function rewind() 131 { 132 $this->position = $this->startRow; 133 } 134 135 /** 136 * Return the current row in this worksheet 137 * 138 * @return PHPExcel_Worksheet_Row 139 */ 140 public function current() 141 { 142 return new PHPExcel_Worksheet_Row($this->subject, $this->position); 143 } 144 145 /** 146 * Return the current iterator key 147 * 148 * @return int 149 */ 150 public function key() 151 { 152 return $this->position; 153 } 154 155 /** 156 * Set the iterator to its next value 157 */ 158 public function next() 159 { 160 ++$this->position; 161 } 162 163 /** 164 * Set the iterator to its previous value 165 */ 166 public function prev() 167 { 168 if ($this->position <= $this->startRow) { 169 throw new PHPExcel_Exception("Row is already at the beginning of range ({$this->startRow} - {$this->endRow})"); 170 } 171 172 --$this->position; 173 } 174 175 /** 176 * Indicate if more rows exist in the worksheet range of rows that we're iterating 177 * 178 * @return boolean 179 */ 180 public function valid() 181 { 182 return $this->position <= $this->endRow; 183 } 184 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |