PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception
Sheet not found for name: {$worksheetReference[0]}
Error message
Sheet not found for name: {$worksheetReference[0]} What it means
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.
Source
Thrown at src/PhpSpreadsheet/Worksheet/Worksheet.php:1249
* Get the correct Worksheet and coordinate from a coordinate that may
* contains reference to another sheet or a named range.
*
* @return array{0: Worksheet, 1: string}
*/
private function getWorksheetAndCoordinate(string $coordinate): array
{
$sheet = null;
$finalCoordinate = null;
// Worksheet reference?
if (str_contains($coordinate, '!')) {
$worksheetReference = self::extractSheetTitle($coordinate, true, true);
$sheet = $this->getParentOrThrow()->getSheetByName($worksheetReference[0]);
$finalCoordinate = strtoupper($worksheetReference[1]);
if ($sheet === null) {
throw new Exception('Sheet not found for name: ' . $worksheetReference[0]);
}
} elseif (
!Preg::isMatch('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $coordinate)
&& Preg::isMatch('/^' . Calculation::CALCULATION_REGEXP_DEFINEDNAME . '$/iu', $coordinate)
) {
// Named range?
$namedRange = $this->validateNamedRange($coordinate, true);
if ($namedRange !== null) {
$sheet = $namedRange->getWorksheet();
if ($sheet === null) {
throw new Exception('Sheet not found for named range: ' . $namedRange->getName());
}
$cellCoordinate = ltrim(substr($namedRange->getValue(), (int) strrpos($namedRange->getValue(), '!')), '!');
$finalCoordinate = str_replace('$', '', $cellCoordinate);
}
}
View on GitHub (pinned to 65b080eef4)
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
Example fix
// before
$cell = $sheet->getCell('Summary!A1'); // throws if 'Summary' does not exist
// after
if ($spreadsheet->getSheetByName('Summary') !== null) {
$cell = $sheet->getCell('Summary!A1');
} Defensive patterns
Strategy: validation
Validate before calling
if ($spreadsheet->getSheetByName($sheetName) !== null) {
$cell = $sheet->getCell("$sheetName!A1");
} else {
// create the sheet or fix the reference
} Try / catch
try {
$cell = $sheet->getCell($ref);
} catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
if (str_contains($e->getMessage(), 'Sheet not found for name:')) {
// skip or repair the reference
} else {
throw $e;
}
} Prevention
- 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
When it happens
Trigger: $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.)
Common situations: 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.
Related errors
- Cannot get column when cell is not bound to a worksheet
- Sheet {$worksheetName} does not exist.
- Workbook does not contain sheet:{$worksheetName}
- Cannot update when cell is not bound to a worksheet
- Cannot get row when cell is not bound to a worksheet
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/67a706dc3270a8e6.
Report an issue: GitHub.