-
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
Default style alignment does not work for Xlsx Writer #3918
Comments
Yes, this definitely appears to be an issue with LibreOffice. As I described it in PR #3459, Excels's implementation of Alignment is "mysterious". To match Excel's behavior, LibreOffice needs to unravel the mystery when reading (and probably writing) am Xlsx spreadsheet, as PhpSpreadsheet has done. |
BTW, I believe LibreOffice has a problem only when Alignment is specified in the default font. As a workaround, you could explicitly specify Alignment on the specific cells which you want aligned. |
Yes, but that means doing so as a second step. Thank you for your help. |
Interestingly, this problem happens when the
However, when the s attribute is explicitly specified as 0 (default), the alignment seems okay.
I might be willing to consider adding an optional parameter to the Xlsx Writer to produce this behavior. But the problem should still be reported to LibreOffice. |
I should admit that I do not know what all of those mean. But I think I understand the different parameters:
Your call, I think that would be great for LibreOffice users. I let you re-open this issue if you want too. I think if it is expected to be omitted to mean "default" then we can keep the current behaviour (without To get a bit more context, how does that work in the
I will report it in the up-coming hours, it does not look like there is an open bug reported for this on https://bugs.documentfoundation.org/buglist.cgi?quicksearch=alignment%20xlsx. |
Your explanation of the xml is correct. Xls format does not use Xml; it uses a proprietary binary format that I'm not particularly familiar with, but one can certainly conjecture that style # for a cell is always present. When you do open your issue with LibreOffice, you might want to, say, set bold in the default style. This will demonstrate that that property is handled correctly even when 's' is omitted from the xml, even though alignment is not. |
I just reported it: https://bugs.documentfoundation.org/show_bug.cgi?id=159916 let's hope they can fix it easily. |
Fix PHPOffice#3918, sort of. Xlsx cells use the default style when they omit the `s` tag, or when `s="0"` is specified. LibreOffice does not honor Alignment in the default Style unless the cell explicitly uses the second form, even though it honors other default Styles (e.g. bold font) when `s` is omitted. Gnumeric seems to have the same problem. A bug report has been filed with LibreOffice. In the meantime, this PR adds to Xlsx Writer an optional boolean property `explicitStyle0` with setter and getter. Default is false, which will continue the current behavior by adding an `s` tag only when the cell uses a non-default style (this is how Excel itself behaves). When set to true, Xlsx Writer will explicity write `s="0"` for all cells using default style. This will allow users to create an Xlsx spreadsheet with default alignment of cells that will show up correctly when the spreadsheet is viewed with LibreOffice. Technically speaking, it is *probably* safe to always use `true`, except that the spreadsheet size will be a bit larger. However, my hope is that this is a temporary measure which can go away when the vendors have had a chance to fix their problems, hence the `false` default.
This is:
What is the expected behavior?
Default alignment style should be applied with
Xlsx
writer.What is the current behavior?
Default alignment style is not applied with
Xlsx
writer.What are the steps to reproduce?
What features do you think are causing the issue
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
It affects
Xlsx
writer but notXls
writer. I did not test for other formatsWhich versions of PhpSpreadsheet and PHP are affected?
At least v2.0.0 (the latest at this time): https://github.com/PHPOffice/PhpSpreadsheet/releases/tag/2.0.0
References
/cc @oleibman as you fixed the other similar issue
Thank you to all maintainers for this awesome library !
The text was updated successfully, but these errors were encountered: