{"record":{"id":"67a706dc3270a8e6","repo":"PHPOffice/PhpSpreadsheet","slug":"sheet-not-found-for-name-worksheetreference-0","errorCode":null,"errorMessage":"Sheet not found for name: {$worksheetReference[0]}","messagePattern":"Sheet not found for name: (.+?)","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/Worksheet.php","lineNumber":1249,"sourceCode":"     * Get the correct Worksheet and coordinate from a coordinate that may\n     * contains reference to another sheet or a named range.\n     *\n     * @return array{0: Worksheet, 1: string}\n     */\n    private function getWorksheetAndCoordinate(string $coordinate): array\n    {\n        $sheet = null;\n        $finalCoordinate = null;\n\n        // Worksheet reference?\n        if (str_contains($coordinate, '!')) {\n            $worksheetReference = self::extractSheetTitle($coordinate, true, true);\n\n            $sheet = $this->getParentOrThrow()->getSheetByName($worksheetReference[0]);\n            $finalCoordinate = strtoupper($worksheetReference[1]);\n\n            if ($sheet === null) {\n                throw new Exception('Sheet not found for name: ' . $worksheetReference[0]);\n            }\n        } elseif (\n            !Preg::isMatch('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $coordinate)\n            && Preg::isMatch('/^' . Calculation::CALCULATION_REGEXP_DEFINEDNAME . '$/iu', $coordinate)\n        ) {\n            // Named range?\n            $namedRange = $this->validateNamedRange($coordinate, true);\n            if ($namedRange !== null) {\n                $sheet = $namedRange->getWorksheet();\n                if ($sheet === null) {\n                    throw new Exception('Sheet not found for named range: ' . $namedRange->getName());\n                }\n\n                $cellCoordinate = ltrim(substr($namedRange->getValue(), (int) strrpos($namedRange->getValue(), '!')), '!');\n                $finalCoordinate = str_replace('$', '', $cellCoordinate);\n            }\n        }\n","sourceCodeStart":1231,"sourceCodeEnd":1267,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/Worksheet.php#L1231-L1267","documentation":"In Worksheet's coordinate resolver (used by getCell() and friends), when a coordinate contains '!' the part before it is treated as a sheet name and looked up with $this->getParentOrThrow()->getSheetByName(). If that lookup returns null — no worksheet with that name in this workbook — the method throws instead of guessing a target.","triggerScenarios":"$sheet->getCell('Summary!A1') when no sheet 'Summary' exists; referencing a sheet by an old name after it was removed/renamed; typos in the sheet portion. (getSheetByName is case-insensitive, but existence is required.)","commonSituations":"Cross-sheet formulas resolved after the referenced sheet was deleted; user-typed references like 'My Sheet!A1' without quotes around the spaced name; importing partial workbooks that lost a sheet.","solutions":["Verify existence first: if ($spreadsheet->getSheetByName($name) === null) { handle } else { $sheet->getCell(\"$name!A1\"); }","Quote sheet names containing spaces: getCell(\"'My Sheet'!A1\")","Fix the reference: recreate/rename the target sheet, or update the stored reference string after renames"],"exampleFix":"// before\n$cell = $sheet->getCell('Summary!A1'); // throws if 'Summary' does not exist\n\n// after\nif ($spreadsheet->getSheetByName('Summary') !== null) {\n    $cell = $sheet->getCell('Summary!A1');\n}","handlingStrategy":"validation","validationCode":"if ($spreadsheet->getSheetByName($sheetName) !== null) {\n    $cell = $sheet->getCell(\"$sheetName!A1\");\n} else {\n    // create the sheet or fix the reference\n}","typeGuard":null,"tryCatchPattern":"try {\n    $cell = $sheet->getCell($ref);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    if (str_contains($e->getMessage(), 'Sheet not found for name:')) {\n        // skip or repair the reference\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Resolve sheet names once up front and cache the Worksheet objects, not name strings","Quote sheet names containing spaces in every reference: \"'My Sheet'!A1\"","After deleting/renaming sheets, sweep stored references that mention them"],"tags":["phpspreadsheet","worksheet","cross-sheet-reference","sheet-not-found","coordinate"],"backgroundTag":"worksheet-not-found","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}