WorksheetIterator.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * PHPExcel_WorksheetIterator
  4. *
  5. * Copyright (c) 2006 - 2015 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
  23. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. class PHPExcel_WorksheetIterator implements Iterator
  28. {
  29. /**
  30. * Spreadsheet to iterate
  31. *
  32. * @var PHPExcel
  33. */
  34. private $subject;
  35. /**
  36. * Current iterator position
  37. *
  38. * @var int
  39. */
  40. private $position = 0;
  41. /**
  42. * Create a new worksheet iterator
  43. *
  44. * @param PHPExcel $subject
  45. */
  46. public function __construct(PHPExcel $subject = null)
  47. {
  48. // Set subject
  49. $this->subject = $subject;
  50. }
  51. /**
  52. * Destructor
  53. */
  54. public function __destruct()
  55. {
  56. unset($this->subject);
  57. }
  58. /**
  59. * Rewind iterator
  60. */
  61. public function rewind()
  62. {
  63. $this->position = 0;
  64. }
  65. /**
  66. * Current PHPExcel_Worksheet
  67. *
  68. * @return PHPExcel_Worksheet
  69. */
  70. public function current()
  71. {
  72. return $this->subject->getSheet($this->position);
  73. }
  74. /**
  75. * Current key
  76. *
  77. * @return int
  78. */
  79. public function key()
  80. {
  81. return $this->position;
  82. }
  83. /**
  84. * Next value
  85. */
  86. public function next()
  87. {
  88. ++$this->position;
  89. }
  90. /**
  91. * More PHPExcel_Worksheet instances available?
  92. *
  93. * @return boolean
  94. */
  95. public function valid()
  96. {
  97. return $this->position < $this->subject->getSheetCount();
  98. }
  99. }