-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Corrupted Xlsx file when generating a chart inside a Sheet #942
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Can you open this issue? Which versions of PhpSpreadsheet and PHP are affected? |
Problem is displayBlanksAs property. I have 2 solution.
|
I checked Solution 1 with the examples from this repository and it works. |
@Mongkol-j Thank you your example is worked fine
|
I google and found possible values of displayBlanksAs are |
This is:
What is the expected behavior?
I want to generated a Chart in an Excel Sheet.
What is the current behavior?
When adding a chart into a sheet, the Xlsx file is generated with success but it show's an error message while opening it in Excel.
"Désolé... Nous avons trouvé un problème dans le contenu de [Nom Fichier], mais nous pouvons récupérer le maximum de contenu. Si la source de ce classeur est fiable, cliquez sur Oui."
After clicking Yes, the Sheet is recovered but the chart is not present into the Sheet.
The error occurs depending on the server operating system.
The same PHP code has been deployed on the 2 server.
What are the steps to reproduce?
Here is the PHP code I use
When adding a chart into a sheet, the Xlsx file is generated with success but it show's an error message while opening it in Excel.
"Désolé... Nous avons trouvé un problème dans le contenu de [Nom Fichier], mais nous pouvons récupérer le maximum de contenu. Si la source de ce classeur est fiable, cliquez sur Oui."
The error occurs depending on the server operating system.
The same PHP code has been deployed on the 2 server.
Comparison of the two files
Into de Xlsx files, just one file is really different. It's the file "xl\chart\chart1.xml".
At the end of the file, there is a difference in the "c:printSettings" at the end.
In the working file, the attributes value for the "c:pageMargins" are number with a point as decimal separator "." separtor (footer="0.3"...).
In the working file, the attributes value for the "c:pageMargins" are number with a comma as decimal separator "." separtor (footer="0.3"...).
It seems the file generator is Os dependant.
Workaround found
I check the \PhpSpreadsheet\Writer\Xlsx\Chart.php file.
The function printSettings has margin attributes hardcoded to float values.
I solved my issues when replacing the float values with string values for the six attributes.
$objWriter->writeAttribute('footer', '0.3');
I'm not sure it's the right solution as I've found the usage of StringHelper::formatNumber() into the \PhpSpreadsheet\Writer\Xlsx\Worksheet.php
Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:
Which versions of PhpSpreadsheet and PHP are affected?
Spreadhseet v1.5.1 / Spreadsheet v1.6.0 (I tried with the two versions).
PHP 5.6
The text was updated successfully, but these errors were encountered: