PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Reader\Exception

Unrecognized attribute flag in tAttr token

Error message

Unrecognized attribute flag in tAttr token

What it means

Inside a tAttr formula token, only specific attribute flags are recognized (volatile, if/else, for, skip, and 0x40/0x41 space variants). The token's flag byte had some other bit pattern set, so the reader refuses to guess the token size and aborts.

Source

Thrown at src/PhpSpreadsheet/Reader/Xls.php:4574

                        $size = 4;
                        // offset: 2; size: 2; space type and position
                        $spacetype = match (ord($formulaData[2])) {
                            0x00 => 'type0',
                            0x01 => 'type1',
                            0x02 => 'type2',
                            0x03 => 'type3',
                            0x04 => 'type4',
                            0x05 => 'type5',
                            default => throw new Exception('Unrecognized space type in tAttrSpace token'),
                        };
                        // offset: 3; size: 1; number of inserted spaces/carriage returns
                        $spacecount = ord($formulaData[3]);

                        $data = ['spacetype' => $spacetype, 'spacecount' => $spacecount];

                        break;
                    default:
                        throw new Exception('Unrecognized attribute flag in tAttr token');
                }

                break;
            case 0x1C:    //    error code
                // offset: 1; size: 1; error code
                $name = 'tErr';
                $size = 2;
                $data = Xls\ErrorCode::lookup(ord($formulaData[1]));

                break;
            case 0x1D:    //    boolean
                // offset: 1; size: 1; 0 = false, 1 = true;
                $name = 'tBool';
                $size = 2;
                $data = ord($formulaData[1]) ? 'TRUE' : 'FALSE';

                break;
            case 0x1E:    //    integer

View on GitHub (pinned to 65b080eef4)

Solutions

  1. Open and re-save the workbook in Excel (or 'Open and Repair') so the formula records are rewritten canonically
  2. Re-export the file from its source system with a current exporter
  3. Confirm the file was not mangled in transit (re-download/re-transfer in binary mode)
  4. Upgrade PhpSpreadsheet in case newly-flagged attributes are supported
Defensive patterns

Strategy: try-catch

Try / catch

try {
    $spreadsheet = IOFactory::load($path);
} catch (\PhpOffice\PhpSpreadsheet\Reader\Exception $e) {
    if (str_contains($e->getMessage(), 'tAttr')) {
        // formula record is nonstandard: request a canonically re-saved file
    }
}

Prevention

When it happens

Trigger: A FORMULA record written with a non-standard grbit in the tAttr token by a third-party BIFF writer, or bit-flipped/corrupted file bytes that turn a valid flag into an unknown one.

Common situations: Workbooks produced by legacy export libraries or converters; files that survived partial disk failure; results of naive byte-level preprocessing (e.g. encoding conversion applied to a binary file).

Related errors


AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17). Data as JSON: /api/errors/cdad917c677a39d7. Report an issue: GitHub.