Closed
Description
When I create a custom reader class, say EchXlsxReader, and register it with registerReader() method, identify method behaves incorrect, returning the class name instead of the type for which it was registered. According to official docs, https://phpspreadsheet.readthedocs.io/en/latest/topics/reading-files/, the following code should work:
/** Identify the type of $inputFileName **/for
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName);
/** Create a new Reader of the type that has been identified **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
/** Load $inputFileName to a Spreadsheet Object **/
$spreadsheet = $reader->load($inputFileName);
But that really doesn't work:
// I register a custom reader to use for XLSX files innstead of standard one.
IOFactory::registerReader(IOFactory::READER_XLSX, EchXlsxReader::class);
...
// The following code will work fine:
$objPHPExcel = IOFactory::load($inputFileName);
// But the code from the mentioned sample fails:
$inputFileType = IOFactory::identify($inputFileName); //Successfully creates the reader and returns "EchXlsxReader"
$objReader = IOFactory::createReader($inputFileType); //Throws error, "No reader found for type EchXlsxReader"
According to the docs the behavior is incorrect, it works for built-in readers just because their (non-qualified) names are equal to the names of the types they read.
Metadata
Metadata
Assignees
Labels
No labels