PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception
Code page $codePage not implemented on this system.
Error message
Code page $codePage not implemented on this system.
What it means
Shared\CodePage::numberToName() maps BIFF code-page IDs (read from .xls CODEPAGE records) to iconv encodings; some IDs map to a list of candidate encodings probed with iconv at runtime. This variant means the code page IS known, but every candidate encoding is unavailable in the system's iconv build, so cell text in the workbook cannot be decoded.
Source
Thrown at src/PhpSpreadsheet/Shared/CodePage.php:98
*
* @param int $codePage Microsoft Code Page Identifier
*
* @return string Code Page Name
*/
public static function numberToName(int $codePage): string
{
if (array_key_exists($codePage, self::$pageArray)) {
$value = self::$pageArray[$codePage];
if (is_array($value)) {
foreach ($value as $encoding) {
if (@iconv('UTF-8', $encoding, ' ') !== false) {
self::$pageArray[$codePage] = $encoding;
return $encoding;
}
}
throw new PhpSpreadsheetException("Code page $codePage not implemented on this system.");
} else {
return $value;
}
}
if ($codePage == 720 || $codePage == 32769) {
throw new PhpSpreadsheetException("Code page $codePage not supported."); // OEM Arabic
}
throw new PhpSpreadsheetException('Unknown codepage: ' . $codePage);
}
/** @return array<int, array<int, string>|string> */
public static function getEncodings(): array
{
return self::$pageArray;
}
}
View on GitHub (pinned to 65b080eef4)
Solutions
- Run the reader in a glibc-based image (Deity/debian-based) or otherwise provide a full iconv build
- Convert the workbook before processing: libreoffice --headless --convert-to xlsx file.xls
- If you control generation, save the .xls with a Unicode code page (UTF-16/UTF-8)
- Verify the runtime: iconv -l | grep -i <encoding> to confirm which encodings exist
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-flight: confirm the runtime iconv supports the encodings your files need
foreach (['IBM437', 'CP850', 'WINDOWS-1252'] as $enc) {
if (@iconv('UTF-8', $enc, ' ') === false) {
throw new RuntimeException("iconv build lacks $enc; use a glibc image");
}
} Try / catch
try {
$spreadsheet = (new \PhpOffice\PhpSpreadsheet\Reader\Xls())->load($path);
} catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
if (str_contains($e->getMessage(), 'Code page')) {
// re-encode the file externally (LibreOffice) and retry once
}
} Prevention
- Prefer glibc-based runtime images over Alpine for legacy .xls processing
- Convert legacy workbooks to .xlsx at ingest time
- Probe iconv availability in smoke tests before deployment
When it happens
Trigger: Reading a legacy .xls whose code page resolves only to encodings compiled out of the runtime iconv (e.g. IBM/EBCDIC pages on minimal builds); reading such a file inside an Alpine/musl-based container where iconv supports only a small encoding set.
Common situations: Docker Alpine images (musl iconv lacks many encodings); PHP built against a minimal libiconv; archived workbooks from mainframe-era or non-Windows locales.
Related errors
- Code page $codePage not supported.
- Unable to get contents of $filename
- Unable to open php://memory
- Unknown codepage: ${codepage}
- Could not open file {filename} for reading.
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/ad198968ea70c008.
Report an issue: GitHub.