Skip to content

Conversation

isleshocky77
Copy link

I have encountered an Excel2003XML file which does not contain styles at all. Due to this the reader throws a warning when trying to iterate over the styles array.

Warning: Invalid argument supplied for foreach() in /vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2003XML.php on line 411

This is:

- [X] a bugfix

Checklist:

Why this change is needed?

See PHPOffice/PHPExcel#558 and PHPOffice/PHPExcel#559

…XML file before iterating

I have encountered an Excel2003XML file which does not contain styles at all. Due to this the reader throws a warning when trying to iterate over the styles array.

> Warning: Invalid argument supplied for foreach() in /vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2003XML.php on line 411
Copy link
Member

@PowerKiKi PowerKiKi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding another nested level, please extract everything into a private method readStyles() which return early if there is no style present.

And add a unit test for that case.

@isleshocky77
Copy link
Author

@PowerKiKi See the Issue and PR from the other project from two years ago. I can't even find the file in question at this point. I broke out the block of code as requested, but that's it.

@PowerKiKi PowerKiKi closed this in 481fc4a Jan 14, 2018
PowerKiKi added a commit that referenced this pull request Jan 28, 2018
- Support for PHP 7.2
- Support cell comments in HTML writer and reader - [#308](#308)
- Option to stop at a conditional styling, if it matches (only XLSX format) - [#292](#292)
- Support for line width for data series when rendering Xlsx - [#329](#329)

- Better auto-detection of CSV separators - [#305](#305)
- Support for shape style ending with `;` - [#304](#304)
- Freeze Panes takes wrong coordinates for XLSX - [#322](#322)
- `COLUMNS` and `ROWS` functions crashed in some cases - [#336](#336)
- Support XML file without styles - [#331](#331)
- Cell coordinates which are already a range cause an exception [#319](#319)
Dfred pushed a commit to Dfred/PhpSpreadsheet that referenced this pull request Nov 20, 2018
Dfred pushed a commit to Dfred/PhpSpreadsheet that referenced this pull request Nov 20, 2018
- Support for PHP 7.2
- Support cell comments in HTML writer and reader - [PHPOffice#308](PHPOffice#308)
- Option to stop at a conditional styling, if it matches (only XLSX format) - [PHPOffice#292](PHPOffice#292)
- Support for line width for data series when rendering Xlsx - [PHPOffice#329](PHPOffice#329)

- Better auto-detection of CSV separators - [PHPOffice#305](PHPOffice#305)
- Support for shape style ending with `;` - [PHPOffice#304](PHPOffice#304)
- Freeze Panes takes wrong coordinates for XLSX - [PHPOffice#322](PHPOffice#322)
- `COLUMNS` and `ROWS` functions crashed in some cases - [PHPOffice#336](PHPOffice#336)
- Support XML file without styles - [PHPOffice#331](PHPOffice#331)
- Cell coordinates which are already a range cause an exception [PHPOffice#319](PHPOffice#319)
BlackyTay pushed a commit to BlackyTay/PhpSpreadsheet that referenced this pull request Aug 8, 2025
BlackyTay pushed a commit to BlackyTay/PhpSpreadsheet that referenced this pull request Aug 8, 2025
- Support for PHP 7.2
- Support cell comments in HTML writer and reader - [PHPOffice#308](PHPOffice#308)
- Option to stop at a conditional styling, if it matches (only XLSX format) - [PHPOffice#292](PHPOffice#292)
- Support for line width for data series when rendering Xlsx - [PHPOffice#329](PHPOffice#329)

- Better auto-detection of CSV separators - [PHPOffice#305](PHPOffice#305)
- Support for shape style ending with `;` - [PHPOffice#304](PHPOffice#304)
- Freeze Panes takes wrong coordinates for XLSX - [PHPOffice#322](PHPOffice#322)
- `COLUMNS` and `ROWS` functions crashed in some cases - [PHPOffice#336](PHPOffice#336)
- Support XML file without styles - [PHPOffice#331](PHPOffice#331)
- Cell coordinates which are already a range cause an exception [PHPOffice#319](PHPOffice#319)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants