Number Format causes fatal errors on copied sheets

Topics: Developer Forum, User Forum
Jul 1, 2009 at 6:58 AM


I load a xls-template via the PHPExcel Reader. Then I copy the active sheet and do my business logic in a loop.
In the loop, I want to set some number formats in my copied template:

$cloned = $objPHPExcel->getActiveSheet()->copy();

$formatCode = PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00; $cloned->getStyle('E15')->getNumberFormat()->setFormatCode($formatCode); $cloned->getStyle('F15')->getNumberFormat()->setFormatCode($formatCode); $cloned->getStyle('G15')->getNumberFormat()->setFormatCode($formatCode); $cloned->getStyle('J15')->getNumberFormat()->setFormatCode($formatCode); $cloned->getStyle('K15')->getNumberFormat()->setFormatCode($formatCode); $cloned->getStyle('L15')->getNumberFormat()->setFormatCode($formatCode); $cloned->getStyle('M15')->getNumberFormat()->setFormatCode($formatCode); $cloned->getStyle('N15')->getNumberFormat()->setFormatCode($formatCode); $cloned->getStyle('O15')->getNumberFormat()->setFormatCode($formatCode); $cloned->getStyle('P15')->getNumberFormat()->setFormatCode($formatCode); $cloned->getStyle('Q15')->getNumberFormat()->setFormatCode($formatCode);

This action will create following fatal error:
Fatal error: Call to a member function getStyle() on a non-object in C:\Zend\Apache2\htdocs\...\lib\phpexcel\PHPExcel\Style\NumberFormat.php on line 280

Would be great if you have any suggestions, how to solve this problem :-)

Kind regards,

Jul 1, 2009 at 12:29 PM

Can you say what version of PHPExcel you are using? Is this happening with latest source code?

Jul 9, 2009 at 9:41 AM

Tested with the latest build 28066.
But today I see that there are some new builds...I'll test my application with the latest build!


Jul 9, 2009 at 1:47 PM

Hmm... That error puzzles me and I cannot reproduce it. Can you post a full sample script?

Also, can you see if you get some notices before the fatal error by putting this at the beginning of your script:


Jul 10, 2009 at 8:39 AM

I'm confused, too.


will show me no further errors...
I copied the code to another file of the project with the result that it works!

In the other file I read in the previously generated file and do some actions there.
It seems to be that this actions cannot be done on cloned sheets.

Do you have an email? I'll send you some code and some demo files...

Jul 11, 2009 at 4:16 AM

>> It seems to be that this actions cannot be done on cloned sheets.

I thought so too, but when I tried there was no problem. You can send me files: erik at phpexcel dot net