{"record":{"id":"54212d68c3b5fafc","repo":"PHPOffice/PhpSpreadsheet","slug":"title-coordinate-message","errorCode":null,"errorMessage":"$title!$coordinate -> $message","messagePattern":"\\$title!\\$coordinate -> \\$message","errorType":"exception","errorClass":"CalculationException","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Cell/Cell.php","lineNumber":608,"sourceCode":"                            if ($row !== $newRow || $column !== $newColumn) {\n                                $thisworksheet->getCell($newColumn . $newRow)->setValue($resultRow);\n                            }\n                            StringHelper::stringIncrement($newColumn);\n                        }\n                    }\n                    $thisworksheet->getCell($column . $row);\n                    $this->value = $originalValue;\n                    $this->dataType = $originalDataType;\n                }\n            } catch (SpreadsheetException $ex) {\n                SharedDate::setExcelCalendar($currentCalendar);\n                if (($ex->getMessage() === 'Unable to access External Workbook') && ($this->calculatedValue !== null)) {\n                    return $this->calculatedValue; // Fallback for calculations referencing external files.\n                } elseif (preg_match('/[Uu]ndefined (name|offset: 2|array key 2)/', $ex->getMessage()) === 1) {\n                    return ExcelError::NAME();\n                }\n\n                throw new CalculationException(\n                    $title . '!' . $this->getCoordinate() . ' -> ' . $ex->getMessage(),\n                    $ex->getCode(),\n                    $ex\n                );\n            }\n            SharedDate::setExcelCalendar($currentCalendar);\n\n            if ($result === Functions::NOT_YET_IMPLEMENTED) {\n                $this->formulaAttributes = $oldAttributes;\n\n                return $this->calculatedValue; // Fallback if calculation engine does not support the formula.\n            }\n\n            return $result;\n        } elseif ($this->value instanceof RichText) {\n            return $this->value->getPlainText();\n        }\n","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Cell/Cell.php#L590-L626","documentation":"When a formula cell is calculated (getCalculatedValue()), errors raised inside the Calculation engine are rethrown as a CalculationException whose message is prefixed with the worksheet title and cell coordinate (e.g. 'Sheet1!B2 -> ...'), with the original SpreadsheetException chained as getPrevious(). The prefix tells you which cell failed; the chained exception carries the real cause. A few engine errors are intercepted first: inaccessible external workbooks fall back to the cached value, and undefined names/offsets map to the #NAME? Excel error.","triggerScenarios":"Formulas referencing sheet titles or defined names that do not exist at calculation time (renamed/removed after load); links to external workbooks that cannot be accessed; corrupt or missing cached values after programmatic sheet manipulation; exotic formulas hitting engine edge cases.","commonSituations":"Loading an xlsx that links other workbooks and recalculating without those files present; renaming/removing sheets while stale formulas still point at old names; batch recalculation over thousands of rows where one broken formula aborts the run.","solutions":["Inspect $e->getPrevious()->getMessage() - the root cause precedes the 'Sheet1!B2 ->' location prefix","Pre-validate references: sheet titles via $spreadsheet->getSheetNames(), defined names via $spreadsheet->getDefinedNames() before recalculating","Wrap per-cell calculation in try/catch so one failure does not abort a batch, logging the location from the message","For external workbook links, make the linked files available or replace the formula with its cached value via $cell->setCalculatedValue($cached)"],"exampleFix":"// before\n$value = $cell->getCalculatedValue(); // CalculationException: Sheet1!B2 -> ...\n\n// after\ntry {\n    $value = $cell->getCalculatedValue();\n} catch (CalculationException $e) {\n    $root = $e->getPrevious(); // original engine error\n    error_log('calc failed at ' . $e->getMessage());\n    $value = null; // or a marker like '#ERROR!'\n}","handlingStrategy":"try-catch","validationCode":"$formula = $cell->getValue();\nif (is_string($formula) && str_starts_with($formula, '=')) {\n    // cheap pre-check: referenced sheet names must exist\n    foreach ($spreadsheet->getSheetNames() as $name) { /* ... */ }\n}\n$value = $cell->getCalculatedValue();","typeGuard":"null","tryCatchPattern":"try {\n    $value = $cell->getCalculatedValue();\n} catch (CalculationException $e) {\n    // message is 'Sheet1!B2 -> root cause'; getPrevious() holds the engine error\n    $this->logger->warning('calc failure: ' . $e->getMessage(), [\n        'root' => $e->getPrevious()?->getMessage(),\n    ]);\n    $value = null; // continue batch instead of aborting\n}","preventionTips":["Treat CalculationException::getPrevious() as the real error and the message prefix as the location","Validate that sheet titles and defined names referenced by formulas still exist before recalculation","Catch CalculationException per cell in batch recalculation so one formula cannot kill the run","Provide external workbook files or pre-set cached values (setCalculatedValue) when links cannot be resolved"],"tags":["phpspreadsheet","formula","calculation","cell-reference","exception-chaining"],"backgroundTag":"formula-evaluation-failed","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}