Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to identify a reader for this file #2907

Closed
han013 opened this issue Jun 23, 2022 · 4 comments
Closed

Unable to identify a reader for this file #2907

han013 opened this issue Jun 23, 2022 · 4 comments

Comments

@han013
Copy link

han013 commented Jun 23, 2022

Importing excel file is prompting an error “Unable to identify a reader for this file”
strict open xml(.xlsx)
test.xlsx

@oleibman
Copy link
Collaborator

Please share your code, PhpSpreadsheet version, Php version. I have no problem identifying a reader for this file (identify returns Xlsx, reader load succeeds):

        $infil = 'issue.2907.xlsx';
        $oufil = 'issue.2907.3.xlsx';
        echo \PhpOffice\PhpSpreadsheet\IOFactory::identify($infil);
        $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile($infil);
        $robj = $reader->load($infil);

        $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($robj, 'Xlsx');
        $writer->save($oufil);
        echo "$oufil has been saved\n";

@oleibman
Copy link
Collaborator

No update in 3 months. Unable to duplicate. Closing.

@jedihe
Copy link

jedihe commented Oct 4, 2023

The bug is reproducible when using PhpSpreadsheet 1.29 in a Drupal 10.0 site. Drupal supports "stream wrapper URIs" (an extended version of PHP streams, with Drupal-specific additions), which may look like 'public://subdir1/public-file.abc', 'private://subdirA/private-file.abc', etc.

For a more detailed repro scenario, check https://drupal.stackexchange.com/questions/275922/why-does-phpspreadsheet-fail-to-identify-my-xlsx-file-in-public

For better context:
PHP streams: https://www.php.net/manual/en/intro.stream.php
Drupal stream wrappers: https://www.drupal.org/docs/7/api/file-api/writing-stream-wrappers#s-stream-wrapper-registry (Written for Drupal 7, but I think it's still valid for D10).

It's quite likely the Drupal case must be handled by glue code in a Drupal module. I guess something like

if (($wrapper = Drupal::service('stream_wrapper_manager')->getViaUri($file_path)) &&
    $wrapper->getType() === StreamWrapperInterface::LOCAL_NORMAL) {
  $file_path = Drupal::service('file_system')->realpath($file_path);
}
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile($file_path);

should do it.

@oleibman
Copy link
Collaborator

This might eventually be handled by PR #3759.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants