Unreadable Content

Topics: Developer Forum, Project Management Forum, User Forum
Apr 2, 2008 at 9:49 PM
After running the 01simple.php with output:

15:42:35 Create new PHPExcel object 15:42:35 Set properties 15:42:35 Add some data 15:42:35 Rename sheet 15:42:35 Write to Excel2007 format 15:42:35 Done writing file. (I commented out the peak_memory line - only change made)

I get the following error when attempting to open the created xlsx:
"Excel found unreadable content in '01simple.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes".

After clicking 'Yes':
"The workbook cannot be opened or repaired by Microsoft Excel because it is corrupt".

I have set the folder permissions to full control for the user needed.

Any ideas?

Apr 3, 2008 at 6:08 AM
Probably something wrong with your phpzip module... Can you rename the .xlsx to .zip and try opening the ZIP file? If that fails, phpzip should be updated. If it succeeds, can you me the file?
Apr 3, 2008 at 5:09 PM
I can explore through the zip file without any problems. Where would you like me to send the file to?

Thanks for all of your help
Apr 3, 2008 at 6:44 PM
You can use maarten AT the name of this project (phpexcel) DOT net. Can you also send me a copy of your PHPInfo and the PHPExcel version number?
Apr 4, 2008 at 5:56 AM
Seems the zip file is corrupt... Try extracting some files in it, it does not work. Can you try upgrading PHP to 5.2.2 ?
Apr 7, 2008 at 8:02 PM
I upgraded PHP to the latest version (5.2.5) and the xlsx file comes out as expected. All of the test files ran and there were no errors/corruption with any of the newly created files.

Thank you for help, it is very appreciated.
Apr 7, 2008 at 8:37 PM
Well, it appears I was just joking when I said there were no errors. Or at least there weren't any "actual" errors.

When I run 08conditionalformatting.php I am having some problems applying styles to some of the cells. Specifically:

B2, B6 and B7 (which would use $objConditional2), the font is green, but the euro symbol is not applied.

Conversely, on cells B3:B5 (the cells using $objConditional1) does apply the euro symbol, however the $objConditional1->getStyle()->getFont()->getColor()->setARGB(PHPExcelStyleColor::COLOR_RED); does not result in a red color format.

In addition, none of the cells are bold, though this line is present: $objConditional1->getStyle()->getFont()->setBold(true); (there is an identical line for $objConditional2)
I have added the following to determine if there is a problem setting the bold, but no Exception is thrown
catch(Exception $e) { print_r($e); }

I tried to search for something of this nature in the other posts, but could not find one. Should I post this as a new thread or just leave it here?

Again, I really appreciate all of your guys obvious hard work. This class has amazing potential.
Apr 7, 2008 at 8:42 PM
On a similar note:


does result in the above cells to be bold.

Maybe I am mis-reading the code and the lines in the previous post should not be bold? Either way, the color and euro-symbol still persist.

I hope I am making sense :-)
Apr 7, 2008 at 8:53 PM
I think I may be onto something here. The lines here:

$conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('B2')->getConditionalStyles();
array_push($conditionalStyles, $objConditional1);
array_push($conditionalStyles, $objConditional2);

$objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet()->getStyle('B2'), 'B3:B7' );

are setting all of the cells B2:B7 to use the conditional formatting. However, something seems odd with applying both of the conditions. In the excel file, editing any of the numbers in B2:B6 will produce the following results:

If the number is positive, or zero
the font will be green, but no euro-symbol is present.
} else {
the euro-symbol will be present, but the font color (red in this case) will not be set

Also, within Excel, going to:
"Conditional Formatting" -> "Manage Rules" -> Show rules for "This Worksheet"
will only show the rules where "Cell Value >= 0" -> Green font
It appears there is no conditional format rule for $objConditional1 at all

I hope this helps in some way...

Apr 7, 2008 at 10:17 PM
I know I am posting a lot, and it may not help with finding my issue, but....

If I change the order in which the $objConditional's are pushed onto the array:
array_push($conditionalStyles, $objConditional2);
array_push($conditionalStyles, $objConditional1);

instead of:
array_push($conditionalStyles, $objConditional1);
array_push($conditionalStyles, $objConditional2);

the lessthan (red) conditional will work (without the euro-symbol). At the same time the GreaterThanOrEqual (green) condition will not work (though the euro-symbol then appears).

Basically it looks like the second condition in the array_push is applied, while the other is not.

As a work around for this, I added the following:
$objConditional3 = new PHPExcelStyleConditional(); //nothing else was done to this object, it was just instanciated
//follow that line with these:
$conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('B2')->getConditionalStyles();
array_push($conditionalStyles, $objConditional3); //push the empty object first
array_push($conditionalStyles, $objConditional1);
array_push($conditionalStyles, $objConditional2);

Doing this did in fact apply both of the conditions to the cells in need. However, none of them have the applied euro-symbol.

I hope that this can help you find this problem if in fact it is a bug.

I'll really try to stop posting until I hear back from someone...

Thanks a bunch for the help!
Apr 8, 2008 at 6:36 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 8, 2008 at 6:45 AM
You spotted an error :-) Fixed in SVN.
Apr 8, 2008 at 3:58 PM
Glad I could help (and that I made sense :-) )

I believe that for this test example, you may also remove lines 82 and 83 (the original setting of the number format) Given that the two conditions will encompass all possible numbers, the setting of the style format which is now done in the $objCondition1/2 should take care of the formatting.

This should not really be a big deal, but it would make for some cleaner code with less processing time.

Just an idea.

Thanks again for your quick help and resolution.
Apr 8, 2008 at 6:42 PM
Right on that one too! Fixed in SVN, will be uploaded here tomorrow morning.