WorksheetIterator.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. class PHPExcel_WorksheetIterator implements Iterator
  8. {
  9. /**
  10. * Spreadsheet to iterate
  11. *
  12. * @var PHPExcel
  13. */
  14. private $subject;
  15. /**
  16. * Current iterator position
  17. *
  18. * @var int
  19. */
  20. private $position = 0;
  21. /**
  22. * Create a new worksheet iterator
  23. *
  24. * @param PHPExcel $subject
  25. */
  26. public function __construct(PHPExcel $subject = null)
  27. {
  28. // Set subject
  29. $this->subject = $subject;
  30. }
  31. /**
  32. * Destructor
  33. */
  34. public function __destruct()
  35. {
  36. unset($this->subject);
  37. }
  38. /**
  39. * Rewind iterator
  40. */
  41. public function rewind()
  42. {
  43. $this->position = 0;
  44. }
  45. /**
  46. * Current PHPExcel_Worksheet
  47. *
  48. * @return PHPExcel_Worksheet
  49. */
  50. public function current()
  51. {
  52. return $this->subject->getSheet($this->position);
  53. }
  54. /**
  55. * Current key
  56. *
  57. * @return int
  58. */
  59. public function key()
  60. {
  61. return $this->position;
  62. }
  63. /**
  64. * Next value
  65. */
  66. public function next()
  67. {
  68. ++$this->position;
  69. }
  70. /**
  71. * More PHPExcel_Worksheet instances available?
  72. *
  73. * @return boolean
  74. */
  75. public function valid()
  76. {
  77. return $this->position < $this->subject->getSheetCount();
  78. }
  79. }