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

Unrecognized space type in tAttrSpace token

Error message

Unrecognized space type in tAttrSpace token

What it means

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.

Source

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

                    case 0x10:
                        $name = 'tAttrSum';
                        $size = 4;
                        $data = null;

                        break;
                    case 0x40:
                    case 0x41:
                        $name = 'tAttrSpace';
                        $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]));

View on GitHub (pinned to 65b080eef4)

Solutions

  1. Open the file in Excel, use Find to locate and re-type the formula in the reported cell, then re-save
  2. Run Excel's 'Open and Repair' and load the repaired copy
  3. If the file comes from your own generator, fix or strip the tAttrSpace emission there
  4. Upgrade PhpSpreadsheet in case the token range was extended in a newer release

Example fix

// before
$spreadsheet = IOFactory::load('report.xls'); // Unrecognized space type in tAttrSpace token

// after: repair pass, then load the fixed copy
shell_exec('soffice --headless --convert-to xls --outdir /tmp report.xls');
$spreadsheet = IOFactory::load('/tmp/report.xls');
Defensive patterns

Strategy: try-catch

Try / catch

try {
    $spreadsheet = IOFactory::load($path);
} catch (\PhpOffice\PhpSpreadsheet\Reader\Exception $e) {
    if (str_contains($e->getMessage(), 'tAttrSpace')) {
        // quarantine file, request a re-saved copy from Excel
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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