-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
This is:
- [x] 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 formats should not be changed when reading then writing an excel file.
What is the current behavior?
Reading an excel file that contains a conditional formatting rule which applies to multiple cells (ie. one rule: $A$1,$C$1,$E1) and then immediately writing the file without making any changes will result in the rule being duplicated so that it only applies to single cells (ie. 1 rule: $A$1, another rule $C$1 and another $E$1).
What are the steps to reproduce?
<?php
require __DIR__ . '/vendor/autoload.php';
// Read the excel file that has a single conditional format applying to multiple cells
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$excel = $reader->load('multili-format.xlsx');
// Immediately write the excel file back out without making any changes
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($excel);
$writer->save('multi-format-output.xlsx');Here is the original file that has no content, and only a a single conditional formatting rule for A1 contains a blank value with the format Not format set
multi-format.xlsx

Here is the output file after running the above script, you can see the conditional formatting rule now has a format of light red fill, dark red text.
multi-format-output.xlsx

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?
- XLSX
Which versions of PhpSpreadsheet and PHP are affected?
- PHP 8.1.2
- PhpSpreadsheet 1.25.2 (1.23.0 also affected)
Anything else?
I'm unsure if this related to #3202 but I imagine the issue is located in the same area?