# tablepress/3.4/libraries/vendor/PhpSpreadsheet/Worksheet/Iterator.php

TablePress – Tables in WordPress made easy, version 3.4. 71 lines.

- Page: https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Worksheet/Iterator.php
- Raw: https://pluginprobe.com/plugins/tablepress/3.4/raw/libraries/vendor/PhpSpreadsheet/Worksheet/Iterator.php
- Modified: 2025-01-08T09:25:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Worksheet/Iterator.php#L10-L20`.

```php
<?php

namespace TablePress\PhpOffice\PhpSpreadsheet\Worksheet;

use TablePress\PhpOffice\PhpSpreadsheet\Spreadsheet;

/**
 * @implements \Iterator<int, Worksheet>
 */
class Iterator implements \Iterator
{
	/**
	 * Spreadsheet to iterate.
	 */
	private Spreadsheet $subject;

	/**
	 * Current iterator position.
	 */
	private int $position = 0;

	/**
	 * Create a new worksheet iterator.
	 */
	public function __construct(Spreadsheet $subject)
	{
		// Set subject
		$this->subject = $subject;
	}

	/**
	 * Rewind iterator.
	 */
	public function rewind(): void
	{
		$this->position = 0;
	}

	/**
	 * Current Worksheet.
	 */
	public function current(): Worksheet
	{
		return $this->subject->getSheet($this->position);
	}

	/**
	 * Current key.
	 */
	public function key(): int
	{
		return $this->position;
	}

	/**
	 * Next value.
	 */
	public function next(): void
	{
		++$this->position;
	}

	/**
	 * Are there more Worksheet instances available?
	 */
	public function valid(): bool
	{
		return $this->position < $this->subject->getSheetCount() && $this->position >= 0;
	}
}

```
