WorksheetIterator.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #[\ReturnTypeWillChange]
  62. public function rewind()
  63. {
  64. $this->position = 0;
  65. }
  66. /**
  67. * Current PHPExcel_Worksheet [修改]
  68. *
  69. * @return PHPExcel_Worksheet
  70. */
  71. #[\ReturnTypeWillChange]
  72. public function current()
  73. {
  74. return $this->subject->getSheet($this->position);
  75. }
  76. /**
  77. * Current key [修改]
  78. *
  79. * @return int
  80. */
  81. #[\ReturnTypeWillChange]
  82. public function key()
  83. {
  84. return $this->position;
  85. }
  86. /**
  87. * Next value [修改]
  88. */
  89. #[\ReturnTypeWillChange]
  90. public function next()
  91. {
  92. ++$this->position;
  93. }
  94. /**
  95. * More PHPExcel_Worksheet instances available? [修改]
  96. *
  97. * @return boolean
  98. */
  99. #[\ReturnTypeWillChange]
  100. public function valid()
  101. {
  102. return $this->position < $this->subject->getSheetCount();
  103. }
  104. }