{"record":{"id":"67ac956ce07bfeb0","repo":"PHPOffice/PhpSpreadsheet","slug":"no-reader-found-for-type-readertype","errorCode":null,"errorMessage":"No reader found for type $readerType","messagePattern":"No reader found for type \\$readerType","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Reader\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/IOFactory.php","lineNumber":117,"sourceCode":"        }\n\n        return new $className($spreadsheet);\n    }\n\n    /**\n     * Create IReader.\n     *\n     * @param array<string, class-string<IReader>> $mergeArray\n     *        Array to use to find reader, self::$readers will be used if $readers is empty.\n     */\n    public static function createReader(string $readerType, array $mergeArray = []): IReader\n    {\n        /** @var class-string<IReader> */\n        $className = $readerType;\n        $readers = empty($mergeArray) ? self::$readers : $mergeArray;\n        if (!in_array($readerType, $readers, true)) {\n            if (!isset($readers[$readerType])) {\n                throw new Reader\\Exception(\"No reader found for type $readerType\");\n            }\n\n            // Instantiate reader\n            $className = $readers[$readerType];\n        }\n\n        return new $className();\n    }\n\n    /**\n     * Loads Spreadsheet from file using automatic Reader\\IReader resolution.\n     *\n     * @param string $filename The name of the spreadsheet file\n     * @param int $flags the optional second parameter flags may be used to identify specific elements\n     *                       that should be loaded, but which won't be loaded by default, using these values:\n     *                            IReader::LOAD_WITH_CHARTS - Include any charts that are defined in the loaded file.\n     *                            IReader::READ_DATA_ONLY - Read cell values only, not formatting or merge structure.\n     *                            IReader::IGNORE_EMPTY_CELLS - Don't load empty cells into the model.","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/IOFactory.php#L99-L135","documentation":"IOFactory::createReader() mirrors the writer factory: the type string must be one of the registered short names ('Xlsx', 'Xls', 'Xml', 'Ods', 'Slk', 'Gnumeric', 'Html', 'Csv' plus registered readers) or a full reader class-string, matched case-sensitively. Anything else throws before the reader is instantiated. An optional $mergeArray overrides the registry for the lookup.","triggerScenarios":"IOFactory::createReader('xlsx') lowercase; 'Excel5'/'Excel2007'/'OOCalc'/'Excel2003XML' (PHPExcel-era names); 'Sylk' instead of the registered key 'Slk'.","commonSituations":"Mapping file extensions to reader types without normalization; migrating legacy PHPExcel code; typos in configuration arrays that name readers.","solutions":["Use the exact keys: 'Xlsx', 'Xls', 'Xml', 'Ods', 'Slk', 'Gnumeric', 'Html', 'Csv'","Map old names: 'Excel2007' -> 'Xlsx', 'Excel5' -> 'Xls', 'OOCalc' -> 'Ods', 'Sylk' -> 'Slk'","Pass a class-string like \\PhpOffice\\PhpSpreadsheet\\Reader\\Xlsx::class to bypass short-name lookup"],"exampleFix":"// before\n$reader = IOFactory::createReader('Excel5');\n\n// after\n$reader = IOFactory::createReader('Xls');","handlingStrategy":"validation","validationCode":"const KNOWN_READERS = ['Xlsx', 'Xls', 'Xml', 'Ods', 'Slk', 'Gnumeric', 'Html', 'Csv'];\n\n/** Normalize arbitrary input (extension, PHPExcel-era name) to a valid reader type. */\nfunction normalizeReaderType(string $type): string\n{\n    $aliases = [\n        'excel2007' => 'Xlsx', 'excel5' => 'Xls', 'oocalc' => 'Ods',\n        'sylk' => 'Slk', 'excel2003xml' => 'Xml',\n    ];\n    $type = $aliases[strtolower(trim($type))] ?? ucfirst(strtolower(trim($type)));\n    if (!in_array($type, KNOWN_READERS, true)\n        && !is_a($type, \\PhpOffice\\PhpSpreadsheet\\Reader\\IReader::class, true)) {\n        throw new InvalidArgumentException(\"Unknown reader type: $type\");\n    }\n\n    return $type;\n}\n\n$reader = IOFactory::createReader(normalizeReaderType($userType));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the exact short names; note the registry key is 'Slk', not 'Sylk'","Test reader-type mappings in CI whenever the library is upgraded","Prefer instantiating concrete readers (new Reader\\Xlsx()) in code paths that always know the format"],"tags":["phpspreadsheet","iofactory","reader","invalid-type"],"backgroundTag":"unknown-reader-type","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}