Replies: 4 comments 2 replies
-
Have you tried the Html Reader? $reader = new \PhpOffice\PhpSpreadsheet\Reader\Html();
$spreadsheet = $reader->load('your.file.name'); |
Beta Was this translation helpful? Give feedback.
-
In that case, I would need to see your file in order to figure out what's going wrong. |
Beta Was this translation helpful? Give feedback.
-
PhpSpreadsheet can read only UTF-8 encoded Html files (without a BOM). Your file is encoded in UTF-16, which is why PhpSpreadsheet considers it unreadable. If the process which generates the file can be changed to generate UTF-8, that would be the easiest solution for you. If the process cannot be changed, and if it is guaranteed to use UTF-16 LE BOM, and if it is guaranteed to not generate a $contents = file_get_contents($infile);
$utf8Contents = mb_convert_encoding($contents, 'UTF-8', 'UTF-16LE');
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader(self::TYP);
$spreadsheet = $reader->loadFromString($utf8Contents); Note that PhpSpreadsheet has no idea what to do with that script tag (which would normally be in the head section of the html), and so sticks it unchanged into cell A1; your "real" data begins in cell A2. Please note that we have evaluated supporting other encodings for html in past, and decided that it is too difficult (note the restriction above on meta tags), and too risky (received some CVE's long ago about non-UTF8 encoding), and, given the extremely heavy predominance of UTF-8 encoding, just not worth it. I can give you a bit more complicated code if you are not sure what the encoding of your file will be. |
Beta Was this translation helpful? Give feedback.
-
Support was added to Html Reader for non-UTF-8 with PR #4019 in May 2024. |
Beta Was this translation helpful? Give feedback.
-
Hey,
I have an Excel file that is exported from a site every hour and must be imported to my site. Unfortunately, the site in question does not have an api that I can directly output from, and it must be done manually by the user.
When I open the file by PhpSpreadsheet, it gives the following error:
Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Reader\Exception: Unable to identify a reader for this file
Apparently, the file format is mso-number-format. Here are the first few lines of the file:
Is there a way I can import this file using PHPOffice and enter it into the database?
Beta Was this translation helpful? Give feedback.
All reactions