{"record":{"id":"29940c22fd91fd7f","repo":"PHPOffice/PhpSpreadsheet","slug":"unrecognized-space-type-in-tattrspace-token","errorCode":null,"errorMessage":"Unrecognized space type in tAttrSpace token","messagePattern":"Unrecognized space type in tAttrSpace token","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Reader\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Reader/Xls.php","lineNumber":4565,"sourceCode":"                    case 0x10:\n                        $name = 'tAttrSum';\n                        $size = 4;\n                        $data = null;\n\n                        break;\n                    case 0x40:\n                    case 0x41:\n                        $name = 'tAttrSpace';\n                        $size = 4;\n                        // offset: 2; size: 2; space type and position\n                        $spacetype = match (ord($formulaData[2])) {\n                            0x00 => 'type0',\n                            0x01 => 'type1',\n                            0x02 => 'type2',\n                            0x03 => 'type3',\n                            0x04 => 'type4',\n                            0x05 => 'type5',\n                            default => throw new Exception('Unrecognized space type in tAttrSpace token'),\n                        };\n                        // offset: 3; size: 1; number of inserted spaces/carriage returns\n                        $spacecount = ord($formulaData[3]);\n\n                        $data = ['spacetype' => $spacetype, 'spacecount' => $spacecount];\n\n                        break;\n                    default:\n                        throw new Exception('Unrecognized attribute flag in tAttr token');\n                }\n\n                break;\n            case 0x1C:    //    error code\n                // offset: 1; size: 1; error code\n                $name = 'tErr';\n                $size = 2;\n                $data = Xls\\ErrorCode::lookup(ord($formulaData[1]));\n","sourceCodeStart":4547,"sourceCodeEnd":4583,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Reader/Xls.php#L4547-L4583","documentation":"While translating a formula's compiled token stream, the reader hit a tAttrSpace token whose space-type byte (offset 2) is outside the documented 0x00-0x05 range. Excel only emits those six values, so anything else indicates a malformed or non-conforming formula record.","triggerScenarios":"Loading an .xls whose formula was written by a third-party generator (reporting tools, old Java/Perl libraries) that emits bogus tAttrSpace payloads, or a FORMULA record damaged by truncation/corruption.","commonSituations":"Spreadsheet 2003-style or BIFF8 exports from legacy enterprise report engines; files transferred in a way that flipped bytes; a single bad formula making the whole workbook unloadable.","solutions":["Open the file in Excel, use Find to locate and re-type the formula in the reported cell, then re-save","Run Excel's 'Open and Repair' and load the repaired copy","If the file comes from your own generator, fix or strip the tAttrSpace emission there","Upgrade PhpSpreadsheet in case the token range was extended in a newer release"],"exampleFix":"// before\n$spreadsheet = IOFactory::load('report.xls'); // Unrecognized space type in tAttrSpace token\n\n// after: repair pass, then load the fixed copy\nshell_exec('soffice --headless --convert-to xls --outdir /tmp report.xls');\n$spreadsheet = IOFactory::load('/tmp/report.xls');","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $spreadsheet = IOFactory::load($path);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Reader\\Exception $e) {\n    if (str_contains($e->getMessage(), 'tAttrSpace')) {\n        // quarantine file, request a re-saved copy from Excel\n    }\n}","preventionTips":["Normalize incoming .xls through LibreOffice/Excel re-save before import","Track producer toolchains that emit nonstandard formula records and fix them at source","Keep PhpSpreadsheet current; token handling gets patched over time"],"tags":["xls","formula","biff","token-parser","phpspreadsheet"],"backgroundTag":"malformed-formula-token","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}