CellIterator.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet\Worksheet;
  3. use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
  4. abstract class CellIterator implements \Iterator
  5. {
  6. /**
  7. * Worksheet to iterate.
  8. *
  9. * @var Worksheet
  10. */
  11. protected $worksheet;
  12. /**
  13. * Iterate only existing cells.
  14. *
  15. * @var bool
  16. */
  17. protected $onlyExistingCells = false;
  18. /**
  19. * Destructor.
  20. */
  21. public function __destruct()
  22. {
  23. unset($this->worksheet);
  24. }
  25. /**
  26. * Get loop only existing cells.
  27. *
  28. * @return bool
  29. */
  30. public function getIterateOnlyExistingCells()
  31. {
  32. return $this->onlyExistingCells;
  33. }
  34. /**
  35. * Validate start/end values for "IterateOnlyExistingCells" mode, and adjust if necessary.
  36. *
  37. * @throws PhpSpreadsheetException
  38. */
  39. abstract protected function adjustForExistingOnlyRange();
  40. /**
  41. * Set the iterator to loop only existing cells.
  42. *
  43. * @param bool $value
  44. *
  45. * @throws PhpSpreadsheetException
  46. */
  47. public function setIterateOnlyExistingCells($value)
  48. {
  49. $this->onlyExistingCells = (bool) $value;
  50. $this->adjustForExistingOnlyRange();
  51. }
  52. }