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

xls file cause the exception during open by Xls reader #402

Closed
odyswise opened this issue Mar 3, 2018 · 27 comments
Closed

xls file cause the exception during open by Xls reader #402

odyswise opened this issue Mar 3, 2018 · 27 comments
Labels
bug help wanted reader/xls Reader for MS BIFF-format (xls) spreadsheet files

Comments

@odyswise
Copy link

odyswise commented Mar 3, 2018

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Excel file opened for reading/write
I tried to use deprecated PhpExcel classes and the file opens successfully!

What is the current behavior?

Trying to open test excel file cause the exception:

Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Reader\Exception: Parameter data is empty. in /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/OLERead.php:331 Stack trace: #0 /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/OLERead.php(281): PhpOffice\PhpSpreadsheet\Shared\OLERead::getInt4d('\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00...', 116) #1 /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/OLERead.php(187): PhpOffice\PhpSpreadsheet\Shared\OLERead->readPropertySets() #2 /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xls.php(1363): PhpOffice\PhpSpreadsheet\Shared\OLERead->read('/tmp/phpk3bjPS') #3 /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xls.php(628): PhpOffice\PhpSpreadsheet\Reader\ in /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/OLERead.php on line 331

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
  $spreadsheet = $reader->load($_FILES['EXP_FILE']['tmp_name']);
  var_dump($spreadsheet->getSheet(0)->getCell('A1')->getValue());die;

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet 1.1 php 7.1

test.zip

@PowerKiKi
Copy link
Member

I can confirm PHPExcel 1.8.1 can read that file, but not PhpSpreadsheet:

<?php

require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/../PHPExcel/Classes/PHPExcel.php';

\PHPExcel_IOFactory::load('test.xls');

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
$reader->load('test.xls');

@chorry
Copy link

chorry commented Mar 12, 2018

From what i've found, example spreadsheet in "test.zip" has a sequence of null-bytes being parsed for property sets.
Due 4b4831b such sequence is considered malformed, therefore
OLERead::getInt4d will throw ReaderException

@odyswise
Copy link
Author

odyswise commented Mar 12, 2018

This file was generated 3rd party software (Scanlister). I understand this file may have mistakes in structure, but LibreOffice, OpenOffice, MS Office opened this files without any errors. I think such files should be supported by PhpSpreadsheet also.

@minorbug
Copy link

Agree with @odyswise.

@ltressens
Copy link

Affected by this bug too. Agreed.

@ChadHydro
Copy link

Also affected by this bug

1 similar comment
@Surely
Copy link

Surely commented Jun 14, 2018

Also affected by this bug

@mythxxx
Copy link

mythxxx commented Jun 14, 2018

+1. cannot parse XLS files previously parsed by phpexcel

@ChadHydro
Copy link

Could any of the devs comment on the priority of this issue? This is unfortunately affecting a critical production system. Would appreciate any insight you could provide. Thanks.

@bkcrisler
Copy link

bkcrisler commented Jun 21, 2018 via email

@inalto
Copy link

inalto commented Jun 29, 2018

Same here, I reverted to phpexcel

@ltressens
Copy link

I have something ugly to handle this case like :

try {
    // use PHPSpreadsheet
}
catch (\Exception $e)
{
   // use PHPExcel
}

I hope a fix is on its way

@maakun12
Copy link

maakun12 commented Jul 6, 2018

affected by this bug

@replay42
Copy link

also affected

@diego3
Copy link

diego3 commented Jul 19, 2018

also affected by this....

@Raftor74
Copy link

I have the same bug.
Here, a fix, that help me:

use PhpOffice\PhpSpreadsheet\Reader\Xls as ExcelReader;
$oldEncoding = "";
$filepath = "test.xls";
if (function_exists("mb_internal_encoding"))
{
	$oldEncoding = mb_internal_encoding();
	mb_internal_encoding('latin1');
	$reader = new PhpOffice\PhpSpreadsheet\Reader\Xls;
	$spreadsheet = $reader->load($filepath);
	mb_internal_encoding($oldEncoding);
}

// Example action
$maxRow = $spreadsheet->getActiveSheet()->getHighestRow();
print_r($maxRow);

@PowerKiKi
Copy link
Member

The faulty commit may have been identified. Would any of you be able to partially revert that commit, test it and submit a PR ?

@m7md3omr
Copy link

also affected, it was nightmare till I found @odyswise comment , everythig work fine after I copy the data to another file and save it, after that code woks fine , thanks @odyswise .

please fix this bug it is nasty and on try catch clause it gives NULL.

@PowerKiKi
Copy link
Member

@Quix0r you wrote the commit that seems to be the source of the issue. Would you share your opinion on this ?

gurrumpalad pushed a commit to gurrumpalad/PhpSpreadsheet that referenced this issue Sep 4, 2018
gurrumpalad pushed a commit to gurrumpalad/PhpSpreadsheet that referenced this issue Oct 2, 2018
gurrumpalad pushed a commit to gurrumpalad/PhpSpreadsheet that referenced this issue Oct 3, 2018
…der PHPOffice#402

 adding unit tests for OLERead and Reader\Xls, also adding changelog entry
gurrumpalad pushed a commit to gurrumpalad/PhpSpreadsheet that referenced this issue Oct 3, 2018
@mirazasx
Copy link

Is this resolved somehow? I'm still experiencing the same issue had to use the old PHPExcel to be able to read files.

@m7md3omr
Copy link

Is this resolved somehow? I'm still experiencing the same issue had to use the old PHPExcel to be able to read files.

you can provide sample file to the users to fill out then upload it, that will save your day :)

@PowerKiKi
Copy link
Member

Should be fixed in 1.5.0

@mirazasx
Copy link

I can't provide an example since it contains sensitive personal data and if I open with LibreOffice and save it then it works. Documents I'm recieving is auto generated by the thirdpart software, some kind of dialer.

I have found out that it doesn't work well with PHPExcel too, but there I had to change one line my self then it works as it should. I'm pretty sure that's not the right fix but it works for me for now.
I have updated Excel5.php line 3744 to:
if (!$this->readDataOnly && !$emptyCell && isset($this->mapCellXfIndex[$xfIndex])) { // add style information $cell->setXfIndex($this->mapCellXfIndex[$xfIndex]); }
It was failing when index at mapCellXfIndex wasn't defined, so after I added isset(....) then it works for me.
Please let me know if there any way I can assist you in order to find and fix this bug :)

@Quix0r
Copy link
Contributor

Quix0r commented Oct 26, 2018

Sorry to cause some mess (?) which was never intended. I'm now with a new employer and PHPExcel (!) is still used here ...

@GianinaSalomo
Copy link

Updating to version 1.5.0 worked for me, but I started getting "undefined index: 0" warnings (like.. a lot...) ... to avoid this, I had to set the reader as setReadDataOnly

@PowerKiKi
Copy link
Member

@GianinaSalomo thanks for reporting back. Maybe you could create a separate issue, linking to this one, with more details about the warnings ?

@garrettburke
Copy link

I had the same issue today trying to load a .xls file ... turns out the file wasn't an .xls, it was actually a tab delimited text file, someone just saved it as .xls

Solved it with the following.

$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Csv');
$reader->setDelimiter("\t");
$spreadsheet = $reader->load($file);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted reader/xls Reader for MS BIFF-format (xls) spreadsheet files
Development

No branches or pull requests