Skip to content
This repository was archived by the owner on Jan 2, 2019. It is now read-only.

Excel2007 Without Styles throws warning #1134

Closed
billynoah opened this issue Feb 21, 2017 · 5 comments
Closed

Excel2007 Without Styles throws warning #1134

billynoah opened this issue Feb 21, 2017 · 5 comments

Comments

@billynoah
Copy link

Similar to this: #558

Warning: Invalid argument supplied for foreach() in Excel2007.php line 555

Line in question is:

foreach ($xmlStyles->cellStyleXfs->xf as $xf) {

Some debugging output:

var_dump($xmlStyles->cellStyleXfs->xf);
NULL

var_dump($xmlStyles->cellStyleXfs);
object(SimpleXMLElement)#656 (0) {}

I opened the xlsx file in question, resaved it and the error is gone. Assuming this error is related to some minor issue in the file. Would still be good to resolve - perhaps just a simple check against the property in question would suffice.

@PowerKiKi
Copy link
Member

We recently merged a commit for a similar issue in PHPOffice/PhpSpreadsheet#95, so I think it would make sense to also solve this one. Would you create a PR against PhpSpreadsheet develop branch ?

@filipposisti
Copy link

filipposisti commented Nov 28, 2017

Hi, i did solve by putting a try{}catch{} at line 555 of Excel2007.php (located at /vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php) file where the

foreach ($xmlStyles->cellStyleXfs->xf as $xf) {

starts. The xlsx style xml does not contain cellStyleXfs tag.

The issue is caused by a wrong interpretation of ISO/IEC 29500-1 standard. The minOccurs="0" for cellStyleXfs which indicates that this element is not required. The application should handle a non-existent cellStyleXfs element. My file was created by fileMaker.

@dnmange
Copy link

dnmange commented Jan 9, 2018

@filipposisti how exactly you resolved did you just put try catch and didn't modified the for loop code, i am getting this bug, thanks for your time.

@filipposisti
Copy link

filipposisti commented Jan 10, 2018

Hi,

the foreach loop is inside a try{}catch{} block

try{
 foreach ($xmlStyles->cellStyleXfs->xf as $xf) {
							
							}
 }catch(Exception $e){

}

just manage the catch part as you want.

Sorry for the bad indenting of the code.

@joakimcarlsten
Copy link

Same thing for me (using phpoffice/phpspreadsheet), generated a file in FileMaker and got this error. Just open and save in Excel and you're good to go.

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

No branches or pull requests

5 participants