Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Worksheet;
   4  
   5  use Iterator;
   6  use PhpOffice\PhpSpreadsheet\Cell\Cell;
   7  use PhpOffice\PhpSpreadsheet\Collection\Cells;
   8  
   9  /**
  10   * @template TKey
  11   *
  12   * @implements Iterator<TKey, Cell>
  13   */
  14  abstract class CellIterator implements Iterator
  15  {
  16      public const TREAT_NULL_VALUE_AS_EMPTY_CELL = 1;
  17  
  18      public const TREAT_EMPTY_STRING_AS_EMPTY_CELL = 2;
  19  
  20      /**
  21       * Worksheet to iterate.
  22       *
  23       * @var Worksheet
  24       */
  25      protected $worksheet;
  26  
  27      /**
  28       * Cell Collection to iterate.
  29       *
  30       * @var Cells
  31       */
  32      protected $cellCollection;
  33  
  34      /**
  35       * Iterate only existing cells.
  36       *
  37       * @var bool
  38       */
  39      protected $onlyExistingCells = false;
  40  
  41      /**
  42       * Destructor.
  43       */
  44      public function __destruct()
  45      {
  46          // @phpstan-ignore-next-line
  47          $this->worksheet = $this->cellCollection = null;
  48      }
  49  
  50      /**
  51       * Get loop only existing cells.
  52       */
  53      public function getIterateOnlyExistingCells(): bool
  54      {
  55          return $this->onlyExistingCells;
  56      }
  57  
  58      /**
  59       * Validate start/end values for "IterateOnlyExistingCells" mode, and adjust if necessary.
  60       */
  61      abstract protected function adjustForExistingOnlyRange();
  62  
  63      /**
  64       * Set the iterator to loop only existing cells.
  65       */
  66      public function setIterateOnlyExistingCells(bool $value): void
  67      {
  68          $this->onlyExistingCells = (bool) $value;
  69  
  70          $this->adjustForExistingOnlyRange();
  71      }
  72  }