Description
This is:
- a bug report
- a feature request
- not a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)
What is the expected behavior?
Conditional formatting rules overlapping the exact same cell range coordinates definition in an Xlsx file get added to the Worksheet's conditionalStylesCollection property.
What is the current behavior?
Conditional formatting rules overlapping the exact same cell range coordinates definition in different definitions in an Xlsx file get overwritten in the Worksheet's conditionalStylesCollection property.
What are the steps to reproduce?
Open and Save a Worksheet that has overlapping conditional styles on the same cell range definition, but spanned over different sqref.
The behavior can be found in /src/Reader/Xlsx/ConditionalStyles.php, in the method ConditionalStyles::setConditionalStyles(Worksheet $worksheet, array $conditionals, SimpleXMLElement $xmlExtLst).
The use of explode doesn't allow taking into account different cell range definitions that span the same range. Having two rules spanning for one "E2:H3" and for the other "E2:H3 E5:H6" will overwrite the conditional formatting of the first rule.
Here is a file showing conditional formatting without errors, that will error out after saving it with PhpSpreadsheet:
test_overlapping_coordinates.xlsx
A dirty fix of array_merge'ing the array of conditionals Worksheet::conditionalStylesCollection with the incoming $styles instead of assigning the incoming array of $styles in Worksheet::setConditionalStyles() fixes the issue for me.
What features do you think are causing the issue
- Reader
- Writer
- Styles
- Data Validations
- Formula Calculations
- Charts
- AutoFilter
- Form Elements
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
I do not know if this affects any other file format than Xlsx.
Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet: 1.29.8
PHP: 8.1