WorksheetIterator.php 2.4 KB

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