You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The original conditional formatting rule priorities get reordered when overwriting an existing Xlsx file containing unsorted rules and rules overlapping cell ranges.
#4312
The original conditional formatting rule priorities are respected when writing an Xlsx file in spite of the overlaps.
What is the current behavior?
The original conditional formatting rule priorities get reordered by order of encounter in the writing loops, leading to the application of rules in the wrong order in various spreadsheet editors (Excel, LibreOffice, OnlyOffice).
What are the steps to reproduce?
Open an Xlsx file containing rules in an unsorted priority order using
The file this extract comes from was written using Microsoft Excel 2016.
The rule priorities are in reverse order from one conditionalFormatting block to the next.
Within the same conditionalFormatting block, the rules are ordered by priorities but are not necessarily successive.
Different conditionalFormatting blocks overlap cell ranges.
Overwriting this file with Phpspreadsheet mangles the priorities such that the first cfRule encountered is now priority 1 instead of 27, the second is priority 2 instead of 13, the third is priority 3 instead of 19, etc... leading to formatting glitches when opening the resulting file in a spreadsheet editor.
What features do you think are causing the issue
Reader
Writer
Styles
Data Validations
Formula Calculations
Charts
AutoFilter
Form Elements
The behavior is located in the method Worksheet::writeConditionalFormatting in the file src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php. The use of a local $id variable internal to the method to write the 'priority' attribute leads to the rule priorities getting reordered.
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
As far as I'm concerned, I've only tested and checked against the Xlsx file format. This behavior may be present in other file format writers.
Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet: 1.29.5 (version I was using) to 3.7.0 (version I have verified contains the same code.)
PHP: 8.1
The text was updated successfully, but these errors were encountered:
I tried to insert your xml into an Excel workbook, but Excel complained of corruption when I tried to open it. Is it possible for you to upload a spreadsheet which has the conditionals defined as above, and which demonstrates your problem? You should be able to clear all the data - I just want to make sure its conditional definitions match what you've reported, and then use it as a basis to investigate the problem.
The corruption probably happened because the workbook didn't contain the corresponding dxfId in /xl/styles.xml.
Here's a stripped-down version of the spreadsheet I'm working with. I have checked the order of priorities I mentioned above was preserved after saving the file, and will be reordered through saving with Phpspreadsheet. Sorry for the French.
I understand some of the rules are... counter-intuitive at best as some defined conditional styles are never shown in the original file considering the given formulae and order of priorities. This is not my file and I'll deal with that with the original author, and I don't believe this has bearing on the issue I'm describing.
This is:
What is the expected behavior?
The original conditional formatting rule priorities are respected when writing an Xlsx file in spite of the overlaps.
What is the current behavior?
The original conditional formatting rule priorities get reordered by order of encounter in the writing loops, leading to the application of rules in the wrong order in various spreadsheet editors (Excel, LibreOffice, OnlyOffice).
What are the steps to reproduce?
Open an Xlsx file containing rules in an unsorted priority order using
Write the same file using
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:
One of the worksheets I'm working with contains this ruleset of conditional formattings, in this order:
The file this extract comes from was written using Microsoft Excel 2016.
Overwriting this file with Phpspreadsheet mangles the priorities such that the first cfRule encountered is now priority 1 instead of 27, the second is priority 2 instead of 13, the third is priority 3 instead of 19, etc... leading to formatting glitches when opening the resulting file in a spreadsheet editor.
What features do you think are causing the issue
The behavior is located in the method Worksheet::writeConditionalFormatting in the file src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php. The use of a local
$id
variable internal to the method to write the 'priority' attribute leads to the rule priorities getting reordered.Does an issue affect all spreadsheet file formats? If not, which formats are affected?
As far as I'm concerned, I've only tested and checked against the Xlsx file format. This behavior may be present in other file format writers.
Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet: 1.29.5 (version I was using) to 3.7.0 (version I have verified contains the same code.)
PHP: 8.1
The text was updated successfully, but these errors were encountered: