Skip to content

Commit 2ed696f

Browse files
authored
Merge pull request #4030 from oleibman/condxls
Xls Conditional Format Improvements
2 parents f2a934a + 623efc0 commit 2ed696f

23 files changed

+147
-64
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2626
### Fixed
2727

2828
- Incorrect Reader CSV with BOM. [Issue #4028](https://github.com/PHPOffice/PhpSpreadsheet/issues/4028) [PR #4029](https://github.com/PHPOffice/PhpSpreadsheet/pull/4029)
29-
- POWER Null/Bool Args. [PR #4031](https://github.com/PHPOffice/PhpSpreadsheet/pull/4031)
29+
- POWER Null/Bool Args. [PR #4031](https://github.com/PHPOffice/PhpSpreadsheet/pull/4031)
30+
- Do Not Output Alignment and Protection for Conditional Format. [Issue #4025](https://github.com/PHPOffice/PhpSpreadsheet/issues/4025) [PR #4027](https://github.com/PHPOffice/PhpSpreadsheet/pull/4027)
31+
- Xls Conditional Format Improvements. [PR #4030](https://github.com/PHPOffice/PhpSpreadsheet/pull/4030)
3032

3133
## 2024-05-11 - 2.1.0
3234

docs/topics/conditional-formatting.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $conditional->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERA
4343
$conditional->addCondition(80);
4444
$conditional->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKGREEN);
4545
$conditional->getStyle()->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID);
46-
$conditional->getStyle()->getFill()->getEndColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN);
46+
$conditional->getStyle()->getFill()->getStartColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN);
4747

4848
$conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('A1:A10')->getConditionalStyles();
4949
$conditionalStyles[] = $conditional;
@@ -63,7 +63,7 @@ $wizard = $wizardFactory->newRule(\PhpOffice\PhpSpreadsheet\Style\ConditionalFor
6363
$wizard->greaterThan(80);
6464
$wizard->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKGREEN);
6565
$wizard->getStyle()->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID);
66-
$wizard->getStyle()->getFill()->getEndColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN);
66+
$wizard->getStyle()->getFill()->getStartColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN);
6767

6868
$conditional = $wizard->getConditional();
6969
```
@@ -84,7 +84,7 @@ $conditional2->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPER
8484
$conditional2->addCondition(10);
8585
$conditional2->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKRED);
8686
$conditional2->getStyle()->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID);
87-
$conditional2->getStyle()->getFill()->getEndColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
87+
$conditional2->getStyle()->getFill()->getStartColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
8888

8989
$conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('A1:A10')->getConditionalStyles();
9090
$conditionalStyles[] = $conditional2;
@@ -98,7 +98,7 @@ $wizard = $wizardFactory->newRule(\PhpOffice\PhpSpreadsheet\Style\ConditionalFor
9898
$wizard->lessThan(10);
9999
$wizard->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKGREEN);
100100
$wizard->getStyle()->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID);
101-
$wizard->getStyle()->getFill()->getEndColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN);
101+
$wizard->getStyle()->getFill()->getStartColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN);
102102

103103
$conditional = $wizard->getConditional();
104104
```

samples/ConditionalFormatting/01_Basic_Comparisons.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,16 @@
7474
$yellowStyle->getFill()
7575
->setFillType(Fill::FILL_SOLID)
7676
->getStartColor()->setARGB(Color::COLOR_YELLOW);
77-
$yellowStyle->getFill()
78-
->getEndColor()->setARGB(Color::COLOR_YELLOW);
7977
$yellowStyle->getFont()->setColor(new Color(Color::COLOR_BLUE));
8078
$greenStyle = new Style(false, true);
8179
$greenStyle->getFill()
8280
->setFillType(Fill::FILL_SOLID)
8381
->getStartColor()->setARGB(Color::COLOR_GREEN);
84-
$greenStyle->getFill()
85-
->getEndColor()->setARGB(Color::COLOR_GREEN);
8682
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
8783
$redStyle = new Style(false, true);
8884
$redStyle->getFill()
8985
->setFillType(Fill::FILL_SOLID)
9086
->getStartColor()->setARGB(Color::COLOR_RED);
91-
$redStyle->getFill()
92-
->getEndColor()->setARGB(Color::COLOR_RED);
9387
$redStyle->getFont()->setColor(new Color(Color::COLOR_GREEN));
9488

9589
// Set conditional formatting rules and styles

samples/ConditionalFormatting/02_Text_Comparisons.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@
7373
$yellowStyle = new Style(false, true);
7474
$yellowStyle->getFill()
7575
->setFillType(Fill::FILL_SOLID)
76-
->getEndColor()->setARGB(Color::COLOR_YELLOW);
76+
->getStartColor()->setARGB(Color::COLOR_YELLOW);
7777
$yellowStyle->getFont()->setColor(new Color(Color::COLOR_BLUE));
7878
$greenStyle = new Style(false, true);
7979
$greenStyle->getFill()
8080
->setFillType(Fill::FILL_SOLID)
81-
->getEndColor()->setARGB(Color::COLOR_GREEN);
81+
->getStartColor()->setARGB(Color::COLOR_GREEN);
8282
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
8383
$redStyle = new Style(false, true);
8484
$redStyle->getFill()
8585
->setFillType(Fill::FILL_SOLID)
86-
->getEndColor()->setARGB(Color::COLOR_RED);
86+
->getStartColor()->setARGB(Color::COLOR_RED);
8787
$redStyle->getFont()->setColor(new Color(Color::COLOR_GREEN));
8888

8989
// Set conditional formatting rules and styles

samples/ConditionalFormatting/03_Blank_Comparisons.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
$greenStyle = new Style(false, true);
4646
$greenStyle->getFill()
4747
->setFillType(Fill::FILL_SOLID)
48-
->getEndColor()->setARGB(Color::COLOR_GREEN);
48+
->getStartColor()->setARGB(Color::COLOR_GREEN);
4949
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
5050
$redStyle = new Style(false, true);
5151
$redStyle->getFill()
5252
->setFillType(Fill::FILL_SOLID)
53-
->getEndColor()->setARGB(Color::COLOR_RED);
53+
->getStartColor()->setARGB(Color::COLOR_RED);
5454
$redStyle->getFont()->setColor(new Color(Color::COLOR_GREEN));
5555

5656
// Set conditional formatting rules and styles

samples/ConditionalFormatting/04_Error_Comparisons.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848
$greenStyle = new Style(false, true);
4949
$greenStyle->getFill()
5050
->setFillType(Fill::FILL_SOLID)
51-
->getEndColor()->setARGB(Color::COLOR_GREEN);
51+
->getStartColor()->setARGB(Color::COLOR_GREEN);
5252
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
5353
$redStyle = new Style(false, true);
5454
$redStyle->getFill()
5555
->setFillType(Fill::FILL_SOLID)
56-
->getEndColor()->setARGB(Color::COLOR_RED);
56+
->getStartColor()->setARGB(Color::COLOR_RED);
5757
$redStyle->getFont()->setColor(new Color(Color::COLOR_GREEN));
5858

5959
// Set conditional formatting rules and styles

samples/ConditionalFormatting/05_Date_Comparisons.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
$yellowStyle = new Style(false, true);
112112
$yellowStyle->getFill()
113113
->setFillType(Fill::FILL_SOLID)
114-
->getEndColor()->setARGB(Color::COLOR_YELLOW);
114+
->getStartColor()->setARGB(Color::COLOR_YELLOW);
115115
$yellowStyle->getFont()->setColor(new Color(Color::COLOR_BLUE));
116116

117117
// Set conditional formatting rules and styles

samples/ConditionalFormatting/06_Duplicate_Comparisons.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454
$yellowStyle = new Style(false, true);
5555
$yellowStyle->getFill()
5656
->setFillType(Fill::FILL_SOLID)
57-
->getEndColor()->setARGB(Color::COLOR_YELLOW);
57+
->getStartColor()->setARGB(Color::COLOR_YELLOW);
5858
$yellowStyle->getFont()->setColor(new Color(Color::COLOR_BLUE));
5959
$greenStyle = new Style(false, true);
6060
$greenStyle->getFill()
6161
->setFillType(Fill::FILL_SOLID)
62-
->getEndColor()->setARGB(Color::COLOR_GREEN);
62+
->getStartColor()->setARGB(Color::COLOR_GREEN);
6363
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
6464

6565
// Set conditional formatting rules and styles

samples/ConditionalFormatting/07_Expression_Comparisons.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@
7373
$yellowStyle = new Style(false, true);
7474
$yellowStyle->getFill()
7575
->setFillType(Fill::FILL_SOLID)
76-
->getEndColor()->setARGB(Color::COLOR_YELLOW);
76+
->getStartColor()->setARGB(Color::COLOR_YELLOW);
7777
$yellowStyle->getFont()->setColor(new Color(Color::COLOR_BLUE));
7878
$greenStyle = new Style(false, true);
7979
$greenStyle->getFill()
8080
->setFillType(Fill::FILL_SOLID)
81-
->getEndColor()->setARGB(Color::COLOR_GREEN);
81+
->getStartColor()->setARGB(Color::COLOR_GREEN);
8282
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
8383

8484
$greenStyleMoney = clone $greenStyle;

src/PhpSpreadsheet/Reader/Xls.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7493,11 +7493,15 @@ private function getCFFillStyle(string $options, Style $style): void
74937493

74947494
// bit: 0-6; mask: 0x007F; type
74957495
$color1 = (0x007F & $fillColors) >> 0;
7496-
$style->getFill()->getStartColor()->setRGB(Xls\Color::map($color1, $this->palette, $this->version)['rgb']);
74977496

74987497
// bit: 7-13; mask: 0x3F80; type
74997498
$color2 = (0x3F80 & $fillColors) >> 7;
7500-
$style->getFill()->getEndColor()->setRGB(Xls\Color::map($color2, $this->palette, $this->version)['rgb']);
7499+
if ($fillPattern === Fill::FILL_SOLID) {
7500+
$style->getFill()->getStartColor()->setRGB(Xls\Color::map($color2, $this->palette, $this->version)['rgb']);
7501+
} else {
7502+
$style->getFill()->getStartColor()->setRGB(Xls\Color::map($color1, $this->palette, $this->version)['rgb']);
7503+
$style->getFill()->getEndColor()->setRGB(Xls\Color::map($color2, $this->palette, $this->version)['rgb']);
7504+
}
75017505
}
75027506
}
75037507

0 commit comments

Comments
 (0)