moodle/moodle · error · PhpOffice\PhpSpreadsheet\Reader\Exception
No reader found for type $readerType
Error message
No reader found for type $readerType
What it means
Thrown by IOFactory::createReader() when the requested reader type name is not a registered reader in IOFactory::$readers. It fires when client code passes an unknown/unregistered type string (e.g. a misspelled format name like 'Xlss' instead of 'Xls', or a custom reader that was never registered via IOFactory::registerReader()). The guard checks in_array($readerType, self::$readers, true), so any type constant not in the built-in list (Xlsx, Xls, Xml, Ods, Slk, Gnumeric, Html, Csv) triggers it.
Solutions
- Use an exact registered reader type, e.g. 'Xlsx'
- Register custom reader: IOFactory::registerReader('MyType', MyReader::class)
- If reading by file, prefer IOfactory::load() / identify() which auto-detects the type
Example fix
// before
$reader = IOFactory::createReader($ext); // $ext = 'xlsxx'
// after
$reader = IOFactory::createReader('Xlsx'); Defensive patterns
Strategy: validation
Validate before calling
if (in_array($type, ['Xlsx','Xls','Csv','Ods','Slk','Xml','Gnumeric'], true)) { $reader = IOFactory::createReader($type); } Try / catch
try { $reader = IOFactory::createReader($type); } catch (\PhpOffice\PhpSpreadsheet\Reader\Exception $e) { $reader = null; } Prevention
- Use exact registered reader names
- Register custom readers before createReader
- Prefer IOFactory::identify()/load() to avoid manual type strings
When it happens
Trigger: IOFactory::createReader('XlsX') or a type never registered (registerReader); only registered keys like 'Xlsx', 'Xls', 'Csv', 'Ods', 'Slk', 'Xml', 'Gnumeric' work.
Common situations: Case-sensitivity mistakes, custom reader formats not registered, string built dynamically from user input or file extension of an unsupported format.
Related errors
- Reader classes must implement their own…
- Reader classes must implement their own listWorksheetInfo()…
- Security scanner is unexpectedly null
- AND Value is only appropriate for range operators
- bstoreContainer is unexpectedly null
AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14).
Data as JSON: /api/errors/5ddd89a542ea7816.
Report an issue: GitHub.
Appendix: source
Thrown at public/lib/phpspreadsheet/phpspreadsheet/src/PhpSpreadsheet/IOFactory.php:85
}
// Instantiate writer
$className = self::$writers[$writerType];
}
return new $className($spreadsheet);
}
/**
* Create IReader.
*/
public static function createReader(string $readerType): IReader
{
/** @var class-string<IReader> */
$className = $readerType;
if (!in_array($readerType, self::$readers, true)) {
if (!isset(self::$readers[$readerType])) {
throw new Reader\Exception("No reader found for type $readerType");
}
// Instantiate reader
$className = self::$readers[$readerType];
}
return new $className();
}
/**
* Loads Spreadsheet from file using automatic Reader\IReader resolution.
*
* @param string $filename The name of the spreadsheet file
* @param int $flags the optional second parameter flags may be used to identify specific elements
* that should be loaded, but which won't be loaded by default, using these values:
* IReader::LOAD_WITH_CHARTS - Include any charts that are defined in the loaded file.
* IReader::READ_DATA_ONLY - Read cell values only, not formatting or merge structure.
* IReader::IGNORE_EMPTY_CELLS - Don't load empty cells into the model.View on GitHub (pinned to 48ea8c3322)