{"record":{"id":"51e8d5746da0f08c","repo":"PHPOffice/PhpSpreadsheet","slug":"row-row-is-out-of-range-this-startrow-th","errorCode":null,"errorMessage":"Row $row is out of range ({$this->startRow} - {$this->endRow})","messagePattern":"Row \\$row is out of range \\((.+?) - (.+?)\\)","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"warning","filePath":"src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php","lineNumber":100,"sourceCode":"    }\n\n    /**\n     * Set the row pointer to the selected row.\n     *\n     * @param int $row The row number to set the current pointer at\n     *\n     * @return $this\n     */\n    public function seek(int $row = 1): static\n    {\n        if (\n            $this->onlyExistingCells\n            && (!$this->cellCollection->has(Coordinate::stringFromColumnIndex($this->columnIndex) . $row))\n        ) {\n            throw new PhpSpreadsheetException('In \"IterateOnlyExistingCells\" mode and Cell does not exist');\n        }\n        if (($row < $this->startRow) || ($row > $this->endRow)) {\n            throw new PhpSpreadsheetException(\"Row $row is out of range ({$this->startRow} - {$this->endRow})\");\n        }\n        $this->currentRow = $row;\n\n        return $this;\n    }\n\n    /**\n     * Rewind the iterator to the starting row.\n     */\n    public function rewind(): void\n    {\n        $this->currentRow = $this->startRow;\n    }\n\n    /**\n     * Return the current cell in this worksheet column.\n     */\n    public function current(): ?Cell","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php#L82-L118","documentation":"ColumnCellIterator::seek() validates the requested row against the iterator's startRow/endRow bounds (defaults derived from the highest row of the column when the iterator was constructed). Seeking outside that window throws with the valid interval in the message.","triggerScenarios":"$cellIterator->seek(500) when the iterator covers rows 1-100; seeking to a row below startRow, e.g. seek(1) after the iterator was created with a start row of 10.","commonSituations":"Random-access navigation on an iterator built for a narrower range; row numbers computed from user input or other sheets assumed to match this column's extent.","solutions":["Seek only within [$iterator->getStartRow()? use the boundaries] — obtain the current bounds or recreate the iterator with the needed range: new ColumnCellIterator($sheet, 'A', 1, 500)","Validate $row against the sheet's highest row ([$sheet->getHighestRow()]) before seeking","Iterate with foreach instead of seek() for sequential access"],"exampleFix":"// before\n$cellIterator->seek(500);\n\n// after\n$row = min(max($row, $cellIterator->getStartRow()), $cellIterator->getEndRow());\n$cellIterator->seek($row);","handlingStrategy":"validation","validationCode":"$row = max($iterator->getStartRow(), min($row, $iterator->getEndRow()));\nif ($row < $iterator->getStartRow() || $row > $iterator->getEndRow()) {\n    throw new OutOfBoundsException(\"Row $row outside iterator bounds\");\n}\n$iterator->seek($row);","typeGuard":"function rowWithinIteratorBounds(\\PhpOffice\\PhpSpreadsheet\\Worksheet\\ColumnCellIterator $it, int $row): bool\n{\n    return $row >= $it->getStartRow() && $row <= $it->getEndRow();\n}","tryCatchPattern":"try {\n    $iterator->seek($row);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    // recreate the iterator covering the requested row\n    $iterator = new \\PhpOffice\\PhpSpreadsheet\\Worksheet\\ColumnCellIterator($sheet, $column, 1, $sheet->getHighestRow());\n    $iterator->seek($row);\n}","preventionTips":["Construct the iterator with the full row span you intend to seek within","Clamp externally derived row numbers to the sheet's highest row"],"tags":["iterator","bounds","row","worksheet","phpspreadsheet"],"backgroundTag":"index-out-of-bounds","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}