Skip to content

TypeError: Illegal offset type in file Xlsx.php on line xxx #2316

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

Closed
terrylinooo opened this issue Oct 6, 2021 · 6 comments
Closed

TypeError: Illegal offset type in file Xlsx.php on line xxx #2316

terrylinooo opened this issue Oct 6, 2021 · 6 comments

Comments

@terrylinooo
Copy link

terrylinooo commented Oct 6, 2021

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?

Load .xlsx file without error.

What is the current behavior?

TypeError: Illegal offset type in file xxxxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php on line 962

What are the steps to reproduce?

Create a spreadsheet from Google Doc, then download it to local disk.
Load the .xlsx file.

Which versions of PhpSpreadsheet and PHP are affected?

1.18

I trace the bug and see this

image

Should check the blue part instead of red part.
I comment out the line and thing goes good now. But I think it should be fixed in here instead of modifying the vendor code.

@oleibman
Copy link
Collaborator

oleibman commented Oct 6, 2021

Can you supply a test file which demonstrates this problem?

@terrylinooo
Copy link
Author

Can you supply a test file which demonstrates this problem?

Thank you for replying.

Here is the link: https://drive.google.com/file/d/1gP1gLFOjDOd8ccScAGYMyYJ-0zYEkMdZ/view?usp=sharing

I checked out the code and found that if I use setReadDataOnly(true) to skip the code block, and everything will work.
If I remove the $reader->setReadDataOnly(true); and then the error occurs.

$type = IOFactory::identify($filePath);
$reader = IOFactory::createReader($type);
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($filePath);

@oleibman
Copy link
Collaborator

oleibman commented Oct 6, 2021

Thank you for supplying the test file. I can confirm that your problem happens with the current release of PhpSpreadsheet. However, there have been changes to master, and I believe that it handles your spreadsheet correctly. Are you able to test against master to confirm?

@terrylinooo
Copy link
Author

Thank you. I will test it again later.

@Michel-Cavaud
Copy link

Hello,
Do you have a date for correcting the problem on the master?
Thank you

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Oct 10, 2021
This change was suggested by issue PHPOffice#2316. There was a problem reading Xlsx comments which appeared with release 18.0 but which was already fixed in master. So no source change was needed to fix the issue, but I thought we should at least add the test case to our unit tests.

In developing that case, I discovered that, although comment text was read correctly, there was a problem with comment author. In fact, there were two problems. One was new, with the namespacing changes - as in several other cases, the namespaced attribute `authorId` needed some special handling. However, another problem was much older - the code was checking `!empty($comment['authorId'])`, eliminating consideration of authorId=0, and should instead have been checking `isset`. Both problems are now fixed, and tested.
@terrylinooo
Copy link
Author

It's okay after upating to master branch.

oleibman added a commit that referenced this issue Oct 24, 2021
This change was suggested by issue #2316. There was a problem reading Xlsx comments which appeared with release 18.0 but which was already fixed in master. So no source change was needed to fix the issue, but I thought we should at least add the test case to our unit tests.

In developing that case, I discovered that, although comment text was read correctly, there was a problem with comment author. In fact, there were two problems. One was new, with the namespacing changes - as in several other cases, the namespaced attribute `authorId` needed some special handling. However, another problem was much older - the code was checking `!empty($comment['authorId'])`, eliminating consideration of authorId=0, and should instead have been checking `isset`. Both problems are now fixed, and tested.
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