{"record":{"id":"7988174fb5cc8363","repo":"PHPOffice/PhpSpreadsheet","slug":"value-could-not-be-bound-to-cell","errorCode":null,"errorMessage":"Value could not be bound to cell.","messagePattern":"Value could not be bound to cell\\.","errorType":"exception","errorClass":"SpreadsheetException","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Cell/Cell.php","lineNumber":119,"sourceCode":"     */\n    public function __construct(mixed $value, ?string $dataType, Worksheet $worksheet)\n    {\n        // Initialise cell value\n        $this->value = $value;\n\n        // Set worksheet cache\n        $this->parent = $worksheet->getCellCollection();\n\n        // Set datatype?\n        if ($dataType !== null) {\n            if ($dataType == DataType::TYPE_STRING2) {\n                $dataType = DataType::TYPE_STRING;\n            }\n            $this->dataType = $dataType;\n        } else {\n            $valueBinder = $worksheet->getParent()?->getValueBinder() ?? self::getValueBinder();\n            if ($valueBinder->bindValue($this, $value) === false) {\n                throw new SpreadsheetException('Value could not be bound to cell.');\n            }\n        }\n        $this->ignoredErrors = new IgnoredErrors();\n    }\n\n    /**\n     * Get cell coordinate column.\n     *\n     * @throws SpreadsheetException\n     */\n    public function getColumn(): string\n    {\n        $parent = $this->parent;\n        if ($parent === null) {\n            throw new SpreadsheetException('Cannot get column when cell is not bound to a worksheet');\n        }\n\n        return $parent->getCurrentColumn();","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Cell/Cell.php#L101-L137","documentation":"When a Cell is constructed with setValue()/getCell() and no explicit data type, PhpSpreadsheet runs the configured IValueBinder (default DefaultValueBinder, optionally AdvancedValueBinder or a custom one). If bindValue() returns false, the constructor throws PhpOffice\\PhpSpreadsheet\\Exception 'Value could not be bound to cell.' - the binder rejected the value. Binders return false for content they cannot classify (e.g. AdvancedValueBinder with unparseable formula-looking strings in some versions, or custom binders enforcing domain rules).","triggerScenarios":"$sheet->getCell('A1')->setValue($value) where the active value binder's bindValue() returns false; Cell::setValueAndOverrideBinder()/setValueExplicit with a custom binder that rejects the value; IValueBinder implementations that return false instead of throwing for invalid input; Cells created directly with new Cell($value, 'A1', $sheet) under such a binder.","commonSituations":"Custom corporate value binders validating types/formats (rejecting e.g. malformed dates or forbidden strings) that signal rejection by returning false; switching DefaultValueBinder -> AdvancedValueBinder and hitting newly-rejected inputs; binder code updated to stricter rules without updating the data feeding it.","solutions":["Inspect your binder: make it throw a meaningful exception (or coerce) instead of returning false, or fix the data it rejects","Set the value with an explicit type to bypass binding: $cell->setValueExplicit($value, DataType::TYPE_STRING)","Pre-validate/sanitize the value in PHP so the binder accepts it","Ensure your IValueBinder implementation never returns false for values you actually need to store"],"exampleFix":"// before: binder rejects -> constructor throws\n$sheet->getCell('A1')->setValue($userInput);\n\n// after: store explicitly without binder interpretation\nuse PhpOffice\\PhpSpreadsheet\\Cell\\DataType;\n$sheet->getCell('A1')->setValueExplicit((string) $userInput, DataType::TYPE_STRING);","handlingStrategy":"fallback","validationCode":"// Know your binder before writing values\n$binder = $sheet->getParent()?->getValueBinder() ?? Cell::getValueBinder();\nif ($binder instanceof MyStrictBinder && !MyStrictBinder::accepts($value)) {\n    $sheet->getCell('A1')->setValueExplicit((string) $value, DataType::TYPE_STRING);\n    return;\n}\n$sheet->getCell('A1')->setValue($value);","typeGuard":"function binderAccepts(\\PhpOffice\\PhpSpreadsheet\\Cell\\IValueBinder $b, mixed $value, \\PhpOffice\\PhpSpreadsheet\\Worksheet\\Worksheet $ws): bool\n{\n    $probe = $ws->getCell((string) max(1, $ws->getHighestRow() + 1) . 'Z' /* scratch cell */);\n    try {\n        $probe->setValue($value);\n        return true;\n    } catch (\\PhpOffice\\PhpSpreadsheet\\Exception) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    $sheet->getCell('A1')->setValue($value);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    if (str_contains($e->getMessage(), 'could not be bound')) {\n        $sheet->getCell('A1')->setValueExplicit((string) $value, DataType::TYPE_STRING);\n    } else { throw $e; }\n}","preventionTips":["Make custom IValueBinder implementations throw descriptive exceptions instead of returning false","Use setValueExplicit($value, DataType::TYPE_...) when you already know the target type and want no binder interpretation","Re-test data pipelines after switching DefaultValueBinder to AdvancedValueBinder","Log rejected values at the binder boundary so 'false' returns never surface as this generic constructor error"],"tags":["phpspreadsheet","cell","value-binder","binding","customization"],"backgroundTag":"value-binding-failed","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}