{"record":{"id":"670de1317080289f","repo":"PHPOffice/PhpSpreadsheet","slug":"unknown-codepage-codepage-670de1","errorCode":null,"errorMessage":"Unknown codepage: $codePage","messagePattern":"Unknown codepage: \\$codePage","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Shared/CodePage.php","lineNumber":107,"sourceCode":"            if (is_array($value)) {\n                foreach ($value as $encoding) {\n                    if (@iconv('UTF-8', $encoding, ' ') !== false) {\n                        self::$pageArray[$codePage] = $encoding;\n\n                        return $encoding;\n                    }\n                }\n\n                throw new PhpSpreadsheetException(\"Code page $codePage not implemented on this system.\");\n            } else {\n                return $value;\n            }\n        }\n        if ($codePage == 720 || $codePage == 32769) {\n            throw new PhpSpreadsheetException(\"Code page $codePage not supported.\"); //    OEM Arabic\n        }\n\n        throw new PhpSpreadsheetException('Unknown codepage: ' . $codePage);\n    }\n\n    /** @return array<int, array<int, string>|string> */\n    public static function getEncodings(): array\n    {\n        return self::$pageArray;\n    }\n}\n","sourceCodeStart":89,"sourceCodeEnd":116,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Shared/CodePage.php#L89-L116","documentation":"CodePage::numberToName() throws 'Unknown codepage' when the ID from the workbook's CODEPAGE record is not in the reader's map at all. That indicates a value outside every BIFF code page PhpSpreadsheet knows — in practice corrupt data, or a file produced by a broken third-party writer rather than Excel.","triggerScenarios":"A corrupted .xls where the CODEPAGE record bytes are garbage; binary malformation from non-Excel generators; forcing the Xls reader onto a file that is not BIFF at all.","commonSituations":"Uploads truncated mid-transfer; files renamed to .xls; aggressive pre-processing or transfer through systems that mangle binary headers (FTP ASCII mode).","solutions":["Verify the file is really an OLE2/BIFF container (leading bytes D0 CF 11 E0 A1 B1 1A E1) or let IOFactory::identify() pick the reader","Re-export or re-download the source file","Repair the file in Excel/LibreOffice first (open + save), then read it","Validate uploads server-side (size, signature) before handing them to the reader"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function looksLikeOle2Spreadsheet(string $path): bool\n{\n    $fh = fopen($path, 'rb');\n    $sig = fread($fh, 8);\n    fclose($fh);\n\n    return $sig === \"\\xD0\\xCF\\x11\\xE0\\xA1\\xB1\\x1A\\xE1\";\n}\n\nif (!looksLikeOle2Spreadsheet($path)) {\n    throw new InvalidArgumentException('Corrupt or non-Xls upload');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $spreadsheet = $reader->load($path);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Reader\\Exception $e) {\n    // 'Unknown codepage' means corrupt/binary-mangled input: quarantine\n    quarantine($path, $e->getMessage());\n}","preventionTips":["Validate the OLE2 signature and file size at the upload boundary","Transfer binary files in binary mode (no FTP ASCII) and verify checksums","Let IOFactory::identify() choose readers instead of forcing Xls"],"tags":["xls","corrupt-file","codepage","file-signature"],"backgroundTag":"unsupported-encoding","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}