# Iterate comments

* Extension version `1.6.0` or later;
* Build with `--enable-reader`;

Iterates every comment on a worksheet via a callback, including both legacy and threaded comments.

## Methods

```php
iterateComments(callable $callback, ?string $sheet = null): bool
```

### **callable $callback**

> Invoked once per comment. Return `false` from the callback to stop iteration.

### **string $sheet**

> Worksheet name. When `null`, the currently `openSheet()`-ed worksheet is used.

## Callback payload

The callback receives an associative array:

* `row` *(int)* — row index (0-based);
* `col` *(int)* — column index (0-based);
* `text` *(string)* — comment body;
* `author` *(string|null)* — author;
* `visible` *(bool)* — whether the comment is permanently visible;
* `threaded` *(bool)* — whether this is a threaded comment;
* `parent_id` *(string|null)* — parent id for threaded replies.

## Return value

`true` on successful completion or callback-driven early exit; `false` on error.

## Example

```php
$config = ['path' => './tests'];
$excel  = new \Vtiful\Kernel\Excel($config);

$excel->openFile('source.xlsx');

$excel->iterateComments(function (array $c) {
    echo "[{$c['author']}] R{$c['row']}C{$c['col']}: {$c['text']}\n";
}, 'Sheet1');
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xlswriter-docs.viest.me/english/reader/iterate-comments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
