diff --git a/Classes/PHPExcel/Worksheet/RowIterator.php b/Classes/PHPExcel/Worksheet/RowIterator.php index 82c6b513..6d81b25c 100644 --- a/Classes/PHPExcel/Worksheet/RowIterator.php +++ b/Classes/PHPExcel/Worksheet/RowIterator.php @@ -19,10 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPExcel - * @package PHPExcel_Worksheet + * @package PHPExcel_Worksheet * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel) - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL - * @version ##VERSION##, ##DATE## + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## */ @@ -32,7 +32,7 @@ * Used to iterate rows in a PHPExcel_Worksheet * * @category PHPExcel - * @package PHPExcel_Worksheet + * @package PHPExcel_Worksheet * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel) */ class PHPExcel_Worksheet_RowIterator extends CachingIterator @@ -51,14 +51,24 @@ class PHPExcel_Worksheet_RowIterator extends CachingIterator */ private $_position = 1; + /** + * Start position + * + * @var int + */ + private $_startRow = 1; + + /** * Create a new row iterator * - * @param PHPExcel_Worksheet $subject + * @param PHPExcel_Worksheet $subject The worksheet to iterate over + * @param integer $startRow The row number at which to start iterating */ - public function __construct(PHPExcel_Worksheet $subject = null) { + public function __construct(PHPExcel_Worksheet $subject = null, $startRow = 1) { // Set subject $this->_subject = $subject; + $this->resetStart($startRow); } /** @@ -69,43 +79,70 @@ class PHPExcel_Worksheet_RowIterator extends CachingIterator } /** - * Rewind iterator + * (Re)Set the start row and the current row pointer + * + * @param integer $startRow The row number at which to start iterating */ - public function rewind() { - $this->_position = 1; - } + public function resetStart($startRow = 1) { + $this->_startRow = $startRow; + $this->seek($startRow); + } - /** - * Current PHPExcel_Worksheet_Row - * - * @return PHPExcel_Worksheet_Row - */ - public function current() { - return new PHPExcel_Worksheet_Row($this->_subject, $this->_position); - } + /** + * Set the row pointer to the selected row + * + * @param integer $row The row number to set the current pointer at + */ + public function seek($row = 1) { + $this->_position = $row; + } - /** - * Current key - * - * @return int - */ - public function key() { - return $this->_position; - } + /** + * Rewind the iterator to the starting row + */ + public function rewind() { + $this->_position = $this->_startRow; + } - /** - * Next value - */ - public function next() { - ++$this->_position; - } + /** + * Return the current row in this worksheet + * + * @return PHPExcel_Worksheet_Row + */ + public function current() { + return new PHPExcel_Worksheet_Row($this->_subject, $this->_position); + } - /** - * More PHPExcel_Worksheet_Row instances available? - * - * @return boolean - */ - public function valid() { - return $this->_position <= $this->_subject->getHighestRow(); - } + /** + * Return the current iterator key + * + * @return int + */ + public function key() { + return $this->_position; + } + + /** + * Set the iterator to its next value + */ + public function next() { + ++$this->_position; + } + + /** + * Set the iterator to its previous value + */ + public function prev() { + if ($this->_position > 1) + --$this->_position; + } + + /** + * Indicate if more rows exist in the worksheet + * + * @return boolean + */ + public function valid() { + return $this->_position <= $this->_subject->getHighestRow(); + } } diff --git a/Classes/PHPExcel/Writer/Excel5.php b/Classes/PHPExcel/Writer/Excel5.php index f64b8deb..1f1e650e 100644 --- a/Classes/PHPExcel/Writer/Excel5.php +++ b/Classes/PHPExcel/Writer/Excel5.php @@ -321,6 +321,7 @@ class PHPExcel_Writer_Excel5 implements PHPExcel_Writer_IWriter foreach ($this->_phpExcel->getAllSheets() as $sheet) { if (count($sheet->getDrawingCollection()) > 0) { $found = true; + break; } } diff --git a/changelog.txt b/changelog.txt index 3928c420..7d466237 100644 --- a/changelog.txt +++ b/changelog.txt @@ -25,6 +25,7 @@ Fixed in SVN: - Feature: (MBaker) Options for cell caching using Igbinary and SQLite/SQlite3. +- Feature: (MBaker) Additional row iterator options: allow a start row to be defined in the constructor; seek(), and prev() methods added. - General: (MBaker) Fix to build to ensure that Examples are included with the documentation - General: (MBaker) Reduce cell caching overhead using dirty flag to ensure that cells are only rewritten to the cache if they have actually been changed - General: (MBaker) Improved memory usage in CSV Writer