Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Worksheet;
   4  
   5  use PhpOffice\PhpSpreadsheet\Spreadsheet;
   6  
   7  class Iterator implements \Iterator
   8  {
   9      /**
  10       * Spreadsheet to iterate.
  11       *
  12       * @var Spreadsheet
  13       */
  14      private $subject;
  15  
  16      /**
  17       * Current iterator position.
  18       *
  19       * @var int
  20       */
  21      private $position = 0;
  22  
  23      /**
  24       * Create a new worksheet iterator.
  25       */
  26      public function __construct(Spreadsheet $subject)
  27      {
  28          // Set subject
  29          $this->subject = $subject;
  30      }
  31  
  32      /**
  33       * Destructor.
  34       */
  35      public function __destruct()
  36      {
  37          $this->subject = null;
  38      }
  39  
  40      /**
  41       * Rewind iterator.
  42       */
  43      public function rewind(): void
  44      {
  45          $this->position = 0;
  46      }
  47  
  48      /**
  49       * Current Worksheet.
  50       *
  51       * @return Worksheet
  52       */
  53      public function current()
  54      {
  55          return $this->subject->getSheet($this->position);
  56      }
  57  
  58      /**
  59       * Current key.
  60       *
  61       * @return int
  62       */
  63      public function key()
  64      {
  65          return $this->position;
  66      }
  67  
  68      /**
  69       * Next value.
  70       */
  71      public function next(): void
  72      {
  73          ++$this->position;
  74      }
  75  
  76      /**
  77       * Are there more Worksheet instances available?
  78       *
  79       * @return bool
  80       */
  81      public function valid()
  82      {
  83          return $this->position < $this->subject->getSheetCount() && $this->position >= 0;
  84      }
  85  }