-
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
conditional style with none border is not preserved when save and load spreadsheet #3370
Comments
Confirmed. When border style is 'none', PhpSpreadsheet is omitting the border tag altogether when writing. This is easily fixed, but exposes another problem - color is automatically set when reading border conditional style even when it is not specified in xml. The combination of the two makes regression problems seem unusually likely, so a fix may take a few days. |
I think the issues with defaults on Conditional Styles go a bit deeper still, see Issue #3202 I'd been trying to figure a way of allowing nullable properties when the Style is Conditional, including the Style itself, but not for normal Cell styling... I hadn't come up with an answer though. |
An additional problem is that the spreadsheet produced by Excel has for its conditional border styles |
Vertical and horizontal appear to not be needed, at least for this particular problem. |
I think we may need to take a step back and look at how Conditional Styles are handled; perhaps we need a separate set of CS classes that extend their corresponding Style classes, but with nullable values and more restricted options; together with a more detailed look at the options available in the different Spreadsheets. |
@MarkBaker I am close to a fix for this problem. I need to write some tests, and also check if it's applicable to the other issue you mentioned. I will have something to push today or tomorrow. Part of the problem is that Border(s) is the only Style element that doesn't have special processing for Conditional. It should have, and that's easy to fix. I will submit the PR as a draft to give you a chance to confirm that it's not thwarting any long-term plans. I won't be able to do anything about vertical/horizontal for the time being. Since a solution for them isn't needed here, that's okay for now. But ... the pseudo-borders are accessible only in Supervisor mode, and the Reader (and probably the Writer) isn't in Supervisor mode when it reads the Conditional Styles and creates the objects. (I do not have a good understanding of Supervisor mode.) |
Fix PHPOffice#3370. Conditional styles are always generated with 5 borders (right, left, top, bottom, diagonal) even though the border style is none in each case. For the spreadsheet in question, top and bottom were inappropriate and interfered with the desired formatting. A new border style, BORDER_OMIT is added which will cause the Xlsx Writer to not generate that style. All conditional borders will be initialized with that value. Any border included in the Xml will, of course, change it to the specified type. Fix PHPOffice#3202. User wants a condition to use "No format set" as you can in Excel. A new boolean property `$noFormatSet`, along with setter and getter, is added to Style/Conditional. It is initialized to false. User can call setter to change it. More importantly for the issue in question, if the Xlsx Reader encounters a `cfRule` tag which does not have a `dxfId` attribute (i.e. no style is associated with the rule), it will set noFormatSet to true. Similarly, the Xlsx writer will not generate a `dfxId` tag when noFormatSet is true. This change is applicable only to Xlsx. Html, Csv, and Ods do not have support for Conditional Formatting. Limited support was added to Xls with PR PHPOffice#2696 in April 2022 and PR PHPOffice#2702 about a month later. However, with the current release code, Xls equivalents of the two new test spreadsheets in this PR are too complicated to be handled correctly by PhpSpreadsheet - loading and then saving them as Xls results in Excel complaining of corruption, and the results don't meet expectations. Since I have no idea how BIFF works, and since the problems with those spreadsheets are not caused by this PR, I am not planning to address those problems at this time.
* WIP Conditional Formatting Improvements for Xlsx Fix #3370. Conditional styles are always generated with 5 borders (right, left, top, bottom, diagonal) even though the border style is none in each case. For the spreadsheet in question, top and bottom were inappropriate and interfered with the desired formatting. A new border style, BORDER_OMIT is added which will cause the Xlsx Writer to not generate that style. All conditional borders will be initialized with that value. Any border included in the Xml will, of course, change it to the specified type. Fix #3202. User wants a condition to use "No format set" as you can in Excel. A new boolean property `$noFormatSet`, along with setter and getter, is added to Style/Conditional. It is initialized to false. User can call setter to change it. More importantly for the issue in question, if the Xlsx Reader encounters a `cfRule` tag which does not have a `dxfId` attribute (i.e. no style is associated with the rule), it will set noFormatSet to true. Similarly, the Xlsx writer will not generate a `dfxId` tag when noFormatSet is true. This change is applicable only to Xlsx. Html, Csv, and Ods do not have support for Conditional Formatting. Limited support was added to Xls with PR #2696 in April 2022 and PR #2702 about a month later. However, with the current release code, Xls equivalents of the two new test spreadsheets in this PR are too complicated to be handled correctly by PhpSpreadsheet - loading and then saving them as Xls results in Excel complaining of corruption, and the results don't meet expectations. Since I have no idea how BIFF works, and since the problems with those spreadsheets are not caused by this PR, I am not planning to address those problems at this time. * Update Documentation, Write Alignment and Font Less Often It doesn't cause any particular harm except for small increases in file size and run time, but Alignment tags are written even when (a) all its attributes are null for Conditional Formatting, and (b) when the xml specifically indicates that Alignment should not be applied. Similarly, Font is written even when all its attributes are null for Conditional Formatting. There are some errors in the Conditional Formatting documentation. Specifying a solid fill color in a Conditional Style requires the use of endColor, not StartColor. The discussion of Order of Evaluating is not entirely accurate. I have changed it to what I believe is an accurate explanation of how Excel works; and also added a mention that other spreadsheet programs might not work the same way, adding a couple of illustrations of the difference. The description of the multiple conditions did not quite match the diagram. 'Stop if true' was a blank paragraph; it is now described, and the new 'No format set' option is described in that paragraph since (I think) it would be used most often in conjunction with 'Stop if true'. * Xlsx Writer Allow StartColor for Conditional Solid Fill To set a solid fill in a non-conditional style, you set StartColor (xml will use that value as fgColor and a default value as bgColor). If you instead set EndColor (xml will use that value as bgColor and a default value as fgColor), the styling will not work as expected. However, for conditional styles, if you set StartColor (xml will use that value as fgColor and not specify bgColor), the styling will not work as expected. If you instead set EndColor (xml will use that value as bgColor and not specify fgColor), the styling will work as expected. Together, this means that you need to use different methods for non-conditional style fill than for conditional style fill. This isn't a big problem, but it is a bit weird. This PR changes Xlsx Writer so that if (a) fill is olid and (b) startColor is specified and (c) endColor is null, the xml will be written as bgColor without specifying fgColor. This means that you can set StartColor for both conditional and non-conditional and get the expected styling. You may, of course, continue to specify EndColor instead for conditional. * Fix Some (Not Many) Xls Problems I will open an issue for the (pre-existing) remainder.
This is:
What is the expected behavior?
conditional style with none border is preserved when save and load spreadsheet.
What is the current behavior?
conditional style with none border is not preserved when save and load spreadsheet.
What are the steps to reproduce?
input.xlsx
output.xlsx
What features do you think are causing the issue
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
only tested in .xlsx.
Which versions of PhpSpreadsheet and PHP are affected?
php 8.2.2
phpoffice/phpspreadsheet 1.27.1
The text was updated successfully, but these errors were encountered: