PHPExcel_Worksheet
[ class tree: PHPExcel_Worksheet ] [ index: PHPExcel_Worksheet ] [ all elements ]

Source for file CellIterator.php

Documentation is available at CellIterator.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2010 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 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.2, 2010-01-11
  26.  */
  27.  
  28.  
  29. /** PHPExcel root directory */
  30. if (!defined('PHPEXCEL_ROOT')) {
  31.     /**
  32.      * @ignore
  33.      */
  34.     define('PHPEXCEL_ROOT'dirname(__FILE__'/../../');
  35. }
  36.  
  37. /** PHPExcel */
  38. require_once PHPEXCEL_ROOT 'PHPExcel.php';
  39.  
  40. /** PHPExcel_Worksheet */
  41. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet.php';
  42.  
  43. /** PHPExcel_Cell */
  44. require_once PHPEXCEL_ROOT 'PHPExcel/Cell.php';
  45.  
  46.  
  47. /**
  48.  * PHPExcel_Worksheet_CellIterator
  49.  * 
  50.  * Used to iterate rows in a PHPExcel_Worksheet
  51.  *
  52.  * @category   PHPExcel
  53.  * @package    PHPExcel_Worksheet
  54.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  55.  */
  56. class PHPExcel_Worksheet_CellIterator extends IteratorIterator
  57. {
  58.     /**
  59.      * PHPExcel_Worksheet to iterate
  60.      *
  61.      * @var PHPExcel_Worksheet 
  62.      */
  63.     private $_subject;
  64.     
  65.     /**
  66.      * Row index
  67.      *
  68.      * @var int 
  69.      */
  70.     private $_rowIndex;
  71.     
  72.     /**
  73.      * Current iterator position
  74.      *
  75.      * @var int 
  76.      */
  77.     private $_position = 0;
  78.     
  79.     /**
  80.      * Loop only existing cells
  81.      *
  82.      * @var boolean 
  83.      */
  84.     private $_onlyExistingCells = true;
  85.  
  86.     /**
  87.      * Create a new cell iterator
  88.      *
  89.      * @param PHPExcel_Worksheet         $subject 
  90.      * @param int                        $rowIndex 
  91.      */
  92.     public function __construct(PHPExcel_Worksheet $subject null$rowIndex 1{
  93.         // Set subject and row index
  94.         $this->_subject     = $subject;
  95.         $this->_rowIndex     = $rowIndex;
  96.     }
  97.     
  98.     /**
  99.      * Destructor
  100.      */
  101.     public function __destruct({
  102.         unset($this->_subject);
  103.     }
  104.     
  105.     /**
  106.      * Rewind iterator
  107.      */
  108.     public function rewind({
  109.         $this->_position = 0;
  110.     }
  111.  
  112.     /**
  113.      * Current PHPExcel_Cell
  114.      *
  115.      * @return PHPExcel_Cell 
  116.      */
  117.     public function current({
  118.         return $this->_subject->getCellByColumnAndRow($this->_position$this->_rowIndex);
  119.     }
  120.  
  121.     /**
  122.      * Current key
  123.      *
  124.      * @return int 
  125.      */
  126.     public function key({
  127.         return $this->_position;
  128.     }
  129.  
  130.     /**
  131.      * Next value
  132.      */
  133.     public function next({
  134.         ++$this->_position;
  135.     }
  136.  
  137.     /**
  138.      * More PHPExcel_Cell instances available?
  139.      *
  140.      * @return boolean 
  141.      */
  142.     public function valid({
  143.         // columnIndexFromString() returns an index based at one,
  144.         // treat it as a count when comparing it to the base zero
  145.         // position.
  146.         $columnCount PHPExcel_Cell::columnIndexFromString($this->_subject->getHighestColumn());
  147.  
  148.         if ($this->_onlyExistingCells{
  149.             // If we aren't looking at an existing cell, either
  150.             // because the first column doesn't exist or next() has
  151.             // been called onto a nonexistent cell, then loop until we
  152.             // find one, or pass the last column.
  153.             while ($this->_position < $columnCount &&
  154.                    !$this->_subject->cellExistsByColumnAndRow($this->_position$this->_rowIndex)) {
  155.                 ++$this->_position;
  156.             }
  157.         }
  158.  
  159.         return $this->_position < $columnCount;
  160.     }
  161.     
  162.     /**
  163.      * Get loop only existing cells
  164.      *
  165.      * @return boolean 
  166.      */
  167.     public function getIterateOnlyExistingCells({
  168.         return $this->_onlyExistingCells;
  169.     }
  170.     
  171.     /**
  172.      * Set loop only existing cells
  173.      *
  174.      * @return boolean 
  175.      */
  176.     public function setIterateOnlyExistingCells($value true{
  177.         $this->_onlyExistingCells = $value;
  178.     }
  179. }

Documentation generated on Mon, 11 Jan 2010 08:07:10 +0100 by phpDocumentor 1.4.1