Skip to content

Commit 762300d

Browse files
author
MarkBaker
committed
Ensure that some CF style is displayed in Xls samples, even while background colour is still a problem, so that it's easy to verify that the rule is beng written correctly
1 parent 2cdffeb commit 762300d

File tree

7 files changed

+65
-11
lines changed

7 files changed

+65
-11
lines changed

samples/ConditionalFormatting/01_Basic_Comparisons.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
->setCellValue('A1', 'Literal Value Comparison')
3131
->setCellValue('A9', 'Value Comparison with Absolute Cell Reference $H$9')
3232
->setCellValue('A17', 'Value Comparison with Relative Cell References')
33-
->setCellValue('A23', 'Value Comparison with Formula based on AVERAGE() ± STDEV()');
33+
->setCellValue('A23', 'Value Comparison with Formula based on AVERAGE() ± STDEV()')
34+
->setCellValue('A30', 'Literal String Value Comparison');
3435

3536
$dataArray = [
3637
[-2, -1, 0, 1, 2],
@@ -45,11 +46,18 @@
4546
[4, 3, 8],
4647
];
4748

49+
$stringArray = [
50+
['I'],
51+
['Love'],
52+
['PHP'],
53+
];
54+
4855
$spreadsheet->getActiveSheet()
4956
->fromArray($dataArray, null, 'A2', true)
5057
->fromArray($dataArray, null, 'A10', true)
5158
->fromArray($betweenDataArray, null, 'A18', true)
5259
->fromArray($dataArray, null, 'A24', true)
60+
->fromArray($stringArray, null, 'A31', true)
5361
->setCellValue('H9', 1);
5462

5563
// Set title row bold
@@ -58,21 +66,31 @@
5866
$spreadsheet->getActiveSheet()->getStyle('A9:E9')->getFont()->setBold(true);
5967
$spreadsheet->getActiveSheet()->getStyle('A17:E17')->getFont()->setBold(true);
6068
$spreadsheet->getActiveSheet()->getStyle('A23:E23')->getFont()->setBold(true);
69+
$spreadsheet->getActiveSheet()->getStyle('A30:E30')->getFont()->setBold(true);
6170

6271
// Define some styles for our Conditionals
6372
$helper->log('Define some styles for our Conditionals');
6473
$yellowStyle = new Style(false, true);
6574
$yellowStyle->getFill()
6675
->setFillType(Fill::FILL_SOLID)
76+
->getStartColor()->setARGB(Color::COLOR_YELLOW);
77+
$yellowStyle->getFill()
6778
->getEndColor()->setARGB(Color::COLOR_YELLOW);
79+
$yellowStyle->getFont()->setColor(new Color(Color::COLOR_BLUE));
6880
$greenStyle = new Style(false, true);
6981
$greenStyle->getFill()
7082
->setFillType(Fill::FILL_SOLID)
83+
->getStartColor()->setARGB(Color::COLOR_GREEN);
84+
$greenStyle->getFill()
7185
->getEndColor()->setARGB(Color::COLOR_GREEN);
86+
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
7287
$redStyle = new Style(false, true);
7388
$redStyle->getFill()
7489
->setFillType(Fill::FILL_SOLID)
90+
->getStartColor()->setARGB(Color::COLOR_RED);
91+
$redStyle->getFill()
7592
->getEndColor()->setARGB(Color::COLOR_RED);
93+
$redStyle->getFont()->setColor(new Color(Color::COLOR_GREEN));
7694

7795
// Set conditional formatting rules and styles
7896
$helper->log('Define conditional formatting and set styles');
@@ -166,6 +184,32 @@
166184
->setStyle($redStyle);
167185
$conditionalStyles[] = $cellWizard->getConditional();
168186

187+
$spreadsheet->getActiveSheet()
188+
->getStyle($cellWizard->getCellRange())
189+
->setConditionalStyles($conditionalStyles);
190+
191+
// Set rules for Value Comparison with String Literal
192+
$cellRange = 'A31:A33';
193+
$formulaRange = implode(
194+
':',
195+
array_map(
196+
[Coordinate::class, 'absoluteCoordinate'],
197+
Coordinate::splitRange($cellRange)[0]
198+
)
199+
);
200+
$conditionalStyles = [];
201+
$wizardFactory = new Wizard($cellRange);
202+
/** @var Wizard\CellValue $cellWizard */
203+
$cellWizard = $wizardFactory->newRule(Wizard::CELL_VALUE);
204+
205+
$cellWizard->equals('LOVE')
206+
->setStyle($redStyle);
207+
$conditionalStyles[] = $cellWizard->getConditional();
208+
209+
$cellWizard->equals('PHP')
210+
->setStyle($greenStyle);
211+
$conditionalStyles[] = $cellWizard->getConditional();
212+
169213
$spreadsheet->getActiveSheet()
170214
->getStyle($cellWizard->getCellRange())
171215
->setConditionalStyles($conditionalStyles);

samples/ConditionalFormatting/02_Text_Comparisons.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@
7474
$yellowStyle->getFill()
7575
->setFillType(Fill::FILL_SOLID)
7676
->getEndColor()->setARGB(Color::COLOR_YELLOW);
77+
$yellowStyle->getFont()->setColor(new Color(Color::COLOR_BLUE));
7778
$greenStyle = new Style(false, true);
7879
$greenStyle->getFill()
7980
->setFillType(Fill::FILL_SOLID)
8081
->getEndColor()->setARGB(Color::COLOR_GREEN);
82+
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
8183
$redStyle = new Style(false, true);
8284
$redStyle->getFill()
8385
->setFillType(Fill::FILL_SOLID)
8486
->getEndColor()->setARGB(Color::COLOR_RED);
87+
$redStyle->getFont()->setColor(new Color(Color::COLOR_GREEN));
8588

8689
// Set conditional formatting rules and styles
8790
$helper->log('Define conditional formatting and set styles');

samples/ConditionalFormatting/03_Blank_Comparisons.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@
4646
$greenStyle->getFill()
4747
->setFillType(Fill::FILL_SOLID)
4848
->getEndColor()->setARGB(Color::COLOR_GREEN);
49+
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
4950
$redStyle = new Style(false, true);
5051
$redStyle->getFill()
5152
->setFillType(Fill::FILL_SOLID)
5253
->getEndColor()->setARGB(Color::COLOR_RED);
54+
$redStyle->getFont()->setColor(new Color(Color::COLOR_GREEN));
5355

5456
// Set conditional formatting rules and styles
5557
$helper->log('Define conditional formatting and set styles');

samples/ConditionalFormatting/04_Error_Comparisons.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@
4949
$greenStyle->getFill()
5050
->setFillType(Fill::FILL_SOLID)
5151
->getEndColor()->setARGB(Color::COLOR_GREEN);
52+
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
5253
$redStyle = new Style(false, true);
5354
$redStyle->getFill()
5455
->setFillType(Fill::FILL_SOLID)
5556
->getEndColor()->setARGB(Color::COLOR_RED);
57+
$redStyle->getFont()->setColor(new Color(Color::COLOR_GREEN));
5658

5759
// Set conditional formatting rules and styles
5860
$helper->log('Define conditional formatting and set styles');

samples/ConditionalFormatting/05_Date_Comparisons.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,11 @@
108108

109109
// Define some styles for our Conditionals
110110
$helper->log('Define some styles for our Conditionals');
111-
112111
$yellowStyle = new Style(false, true);
113112
$yellowStyle->getFill()
114113
->setFillType(Fill::FILL_SOLID)
115114
->getEndColor()->setARGB(Color::COLOR_YELLOW);
116-
$yellowStyle->getNumberFormat()->setFormatCode('ddd dd-mmm-yyyy');
115+
$yellowStyle->getFont()->setColor(new Color(Color::COLOR_BLUE));
117116

118117
// Set conditional formatting rules and styles
119118
$helper->log('Define conditional formatting and set styles');

samples/ConditionalFormatting/06_Duplicate_Comparisons.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@
5151

5252
// Define some styles for our Conditionals
5353
$helper->log('Define some styles for our Conditionals');
54-
$greenStyle = new Style(false, true);
55-
$greenStyle->getFill()
56-
->setFillType(Fill::FILL_SOLID)
57-
->getEndColor()->setARGB(Color::COLOR_GREEN);
5854
$yellowStyle = new Style(false, true);
5955
$yellowStyle->getFill()
6056
->setFillType(Fill::FILL_SOLID)
6157
->getEndColor()->setARGB(Color::COLOR_YELLOW);
58+
$yellowStyle->getFont()->setColor(new Color(Color::COLOR_BLUE));
59+
$greenStyle = new Style(false, true);
60+
$greenStyle->getFill()
61+
->setFillType(Fill::FILL_SOLID)
62+
->getEndColor()->setARGB(Color::COLOR_GREEN);
63+
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
6264

6365
// Set conditional formatting rules and styles
6466
$helper->log('Define conditional formatting and set styles');

samples/ConditionalFormatting/07_Expression_Comparisons.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,16 @@
6969

7070
// Define some styles for our Conditionals
7171
$helper->log('Define some styles for our Conditionals');
72-
$greenStyle = new Style(false, true);
73-
$greenStyle->getFill()
74-
->setFillType(Fill::FILL_SOLID)
75-
->getEndColor()->setARGB(Color::COLOR_GREEN);
7672
$yellowStyle = new Style(false, true);
7773
$yellowStyle->getFill()
7874
->setFillType(Fill::FILL_SOLID)
7975
->getEndColor()->setARGB(Color::COLOR_YELLOW);
76+
$yellowStyle->getFont()->setColor(new Color(Color::COLOR_BLUE));
77+
$greenStyle = new Style(false, true);
78+
$greenStyle->getFill()
79+
->setFillType(Fill::FILL_SOLID)
80+
->getEndColor()->setARGB(Color::COLOR_GREEN);
81+
$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED));
8082

8183
$greenStyleMoney = clone $greenStyle;
8284
$greenStyleMoney->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_ACCOUNTING_USD);

0 commit comments

Comments
 (0)