{"record":{"id":"135e54fd9b8c7be1","repo":"PHPOffice/PhpSpreadsheet","slug":"value-135e54","errorCode":null,"errorMessage":"#VALUE!","messagePattern":"#VALUE!","errorType":"exception","errorClass":"PhpSpreadsheet\\Calculation\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Calculation/Engineering/ConvertBase.php","lineNumber":19,"sourceCode":"<?php\n\nnamespace PhpOffice\\PhpSpreadsheet\\Calculation\\Engineering;\n\nuse PhpOffice\\PhpSpreadsheet\\Calculation\\ArrayEnabled;\nuse PhpOffice\\PhpSpreadsheet\\Calculation\\Exception;\nuse PhpOffice\\PhpSpreadsheet\\Calculation\\Functions;\nuse PhpOffice\\PhpSpreadsheet\\Calculation\\Information\\ExcelError;\nuse PhpOffice\\PhpSpreadsheet\\Shared\\StringHelper;\n\nabstract class ConvertBase\n{\n    use ArrayEnabled;\n\n    protected static function validateValue(mixed $value): string\n    {\n        if (is_bool($value)) {\n            if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) {\n                throw new Exception(ExcelError::VALUE());\n            }\n            $value = (int) $value;\n        }\n\n        if (is_numeric($value)) {\n            if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {\n                $value = floor((float) $value);\n            }\n        }\n\n        return strtoupper(StringHelper::convertToString($value));\n    }\n\n    protected static function validatePlaces(mixed $places = null): ?int\n    {\n        if ($places === null) {\n            return $places;\n        }","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Calculation/Engineering/ConvertBase.php#L1-L37","documentation":"#VALUE! from the base-conversion validator (ConvertBase::validateValue) shared by BIN2DEC/BIN2HEX/BIN2OCT, DEC2BIN/DEC2HEX/DEC2OCT, HEX2* and OCT2*. A boolean value is only tolerated in OpenOffice compatibility mode; in the default Excel (and Gnumeric) mode is_bool($value) throws Calculation\\Exception('#VALUE!'), returned as the result string.","triggerScenarios":"=BIN2DEC(TRUE()) with default compatibility; ConvertBinary::toDecimal(true) from PHP; conversion functions applied to cells holding TRUE/FALSE values. Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE) switches the behaviour: TRUE becomes 1, FALSE becomes 0.","commonSituations":"Reading boolean cells or boolean API/JSON values and feeding them into conversion functions; replicating LibreOffice results in a pipeline that runs with Excel compatibility; spreadsheets authored in OpenOffice behaving differently after import.","solutions":["Cast booleans to int before calling the conversion functions: (int) $value.","If you deliberately need OpenOffice semantics, set Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE) once at bootstrap - but expect other behavioural differences.","Filter boolean cells out of conversion inputs when importing mixed-type sheets."],"exampleFix":"// before\n$dec = ConvertBinary::toDecimal($cellValue); // true -> '#VALUE!'\n\n// after\n$dec = ConvertBinary::toDecimal(is_bool($cellValue) ? (int) $cellValue : $cellValue);","handlingStrategy":"type-guard","validationCode":"if (is_bool($value)) {\n    $value = (int) $value; // Excel-mode equivalent of OpenOffice coercion\n}\n$dec = ConvertBinary::toDecimal($value);","typeGuard":"/** Base-conversion inputs must not be boolean (except in OpenOffice mode). */\nfunction isAcceptableConversionValue(mixed $v): bool\n{\n    return !is_bool($v);\n}","tryCatchPattern":null,"preventionTips":["Convert TRUE/FALSE cells to 1/0 before BIN2*/DEC2*/HEX2*/OCT2* calls.","If you must mirror LibreOffice, call Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE) once - and audit other behavioural differences.","Branch on DataType::TYPE_BOOL when walking imported sheets."],"tags":["phpspreadsheet","excel-formula","base-conversion","boolean-input","compatibility-mode"],"backgroundTag":"excel-value-error","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}