{"record":{"id":"ade7cc1709634a5b","repo":"PHPOffice/PhpSpreadsheet","slug":"unknown-codepage-codepage","errorCode":null,"errorMessage":"Unknown codepage: ${codepage}","messagePattern":"Unknown codepage: (.+?)","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Reader/XlsBase.php","lineNumber":139,"sourceCode":"        Border::BORDER_DASHDOT, // => 0x09,\n        Border::BORDER_MEDIUMDASHDOT, // => 0x0A,\n        Border::BORDER_DASHDOTDOT, // => 0x0B,\n        Border::BORDER_MEDIUMDASHDOTDOT, // => 0x0C,\n        Border::BORDER_SLANTDASHDOT, // => 0x0D,\n        Border::BORDER_OMIT, // => 0x0E,\n        Border::BORDER_OMIT, // => 0x0F,\n    ];\n\n    /**\n     * Codepage set in the Excel file being read. Only important for BIFF5 (Excel 5.0 - Excel 95)\n     * For BIFF8 (Excel 97 - Excel 2003) this will always have the value 'UTF-16LE'.\n     */\n    protected string $codepage = '';\n\n    public function setCodepage(string $codepage): void\n    {\n        if (CodePage::validate($codepage) === false) {\n            throw new PhpSpreadsheetException('Unknown codepage: ' . $codepage);\n        }\n\n        $this->codepage = $codepage;\n    }\n\n    public function getCodepage(): string\n    {\n        return $this->codepage;\n    }\n\n    /**\n     * Can the current IReader read the file?\n     */\n    public function canRead(string $filename): bool\n    {\n        if (File::testFileNoThrow($filename) === false) {\n            return false;\n        }","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Reader/XlsBase.php#L121-L157","documentation":"XlsBase::setCodepage() rejects any codepage string that CodePage::validate() does not recognize. The codepage only matters for BIFF5 (Excel 5/95) strings; BIFF8 files are always UTF-16LE internally and do not need one.","triggerScenarios":"Calling $reader->setCodepage('UTF-8') or another generic encoding name instead of a Microsoft codepage identifier like 'CP1252'; typos such as 'cp-1252'; passing an encoding mb_convert_encoding knows but the CodePage table does not.","commonSituations":"Copy-pasting an iconv/mb_list_encodings name into setCodepage; upgrading code from very old PHPExcel examples that used different codepage naming.","solutions":["Pass a Microsoft codepage name understood by the table, e.g. 'CP1252' (Western European), 'CP1251', 'CP932', 'CP936'","Validate first with CodePage::validate($cp) before calling setCodepage","If the file is BIFF8 (Excel 97-2003), do not set a codepage at all — it is ignored/unnecessary"],"exampleFix":"// before\n$reader = new \\PhpOffice\\PhpSpreadsheet\\Reader\\Xls();\n$reader->setCodepage('UTF-8'); // Unknown codepage: UTF-8\n\n// after\n$reader = new \\PhpOffice\\PhpSpreadsheet\\Reader\\Xls();\n$cp = 'CP1252';\nif (\\PhpOffice\\PhpSpreadsheet\\Shared\\CodePage::validate($cp)) {\n    $reader->setCodepage($cp);\n}","handlingStrategy":"validation","validationCode":"use \\PhpOffice\\PhpSpreadsheet\\Shared\\CodePage;\n$cp = 'CP1252';\nif (CodePage::validate($cp)) {\n    $reader->setCodepage($cp);\n}","typeGuard":"function isKnownCodepage(string $cp): bool\n{\n    return \\PhpOffice\\PhpSpreadsheet\\Shared\\CodePage::validate($cp);\n}","tryCatchPattern":null,"preventionTips":["Only set a codepage for BIFF5 (Excel 5/95) files; BIFF8 needs none","Use Microsoft codepage names ('CP1252'), not generic encoding names ('UTF-8', 'ISO-8859-1')","Validate with CodePage::validate() before assigning"],"tags":["xls","biff5","codepage","encoding","phpspreadsheet"],"backgroundTag":"unknown-codepage","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}