|
30 | 30 | ->setCellValue('A1', 'Literal Value Comparison') |
31 | 31 | ->setCellValue('A9', 'Value Comparison with Absolute Cell Reference $H$9') |
32 | 32 | ->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'); |
34 | 35 |
|
35 | 36 | $dataArray = [ |
36 | 37 | [-2, -1, 0, 1, 2], |
|
45 | 46 | [4, 3, 8], |
46 | 47 | ]; |
47 | 48 |
|
| 49 | +$stringArray = [ |
| 50 | + ['I'], |
| 51 | + ['Love'], |
| 52 | + ['PHP'], |
| 53 | +]; |
| 54 | + |
48 | 55 | $spreadsheet->getActiveSheet() |
49 | 56 | ->fromArray($dataArray, null, 'A2', true) |
50 | 57 | ->fromArray($dataArray, null, 'A10', true) |
51 | 58 | ->fromArray($betweenDataArray, null, 'A18', true) |
52 | 59 | ->fromArray($dataArray, null, 'A24', true) |
| 60 | + ->fromArray($stringArray, null, 'A31', true) |
53 | 61 | ->setCellValue('H9', 1); |
54 | 62 |
|
55 | 63 | // Set title row bold |
|
58 | 66 | $spreadsheet->getActiveSheet()->getStyle('A9:E9')->getFont()->setBold(true); |
59 | 67 | $spreadsheet->getActiveSheet()->getStyle('A17:E17')->getFont()->setBold(true); |
60 | 68 | $spreadsheet->getActiveSheet()->getStyle('A23:E23')->getFont()->setBold(true); |
| 69 | +$spreadsheet->getActiveSheet()->getStyle('A30:E30')->getFont()->setBold(true); |
61 | 70 |
|
62 | 71 | // Define some styles for our Conditionals |
63 | 72 | $helper->log('Define some styles for our Conditionals'); |
64 | 73 | $yellowStyle = new Style(false, true); |
65 | 74 | $yellowStyle->getFill() |
66 | 75 | ->setFillType(Fill::FILL_SOLID) |
| 76 | + ->getStartColor()->setARGB(Color::COLOR_YELLOW); |
| 77 | +$yellowStyle->getFill() |
67 | 78 | ->getEndColor()->setARGB(Color::COLOR_YELLOW); |
| 79 | +$yellowStyle->getFont()->setColor(new Color(Color::COLOR_BLUE)); |
68 | 80 | $greenStyle = new Style(false, true); |
69 | 81 | $greenStyle->getFill() |
70 | 82 | ->setFillType(Fill::FILL_SOLID) |
| 83 | + ->getStartColor()->setARGB(Color::COLOR_GREEN); |
| 84 | +$greenStyle->getFill() |
71 | 85 | ->getEndColor()->setARGB(Color::COLOR_GREEN); |
| 86 | +$greenStyle->getFont()->setColor(new Color(Color::COLOR_DARKRED)); |
72 | 87 | $redStyle = new Style(false, true); |
73 | 88 | $redStyle->getFill() |
74 | 89 | ->setFillType(Fill::FILL_SOLID) |
| 90 | + ->getStartColor()->setARGB(Color::COLOR_RED); |
| 91 | +$redStyle->getFill() |
75 | 92 | ->getEndColor()->setARGB(Color::COLOR_RED); |
| 93 | +$redStyle->getFont()->setColor(new Color(Color::COLOR_GREEN)); |
76 | 94 |
|
77 | 95 | // Set conditional formatting rules and styles |
78 | 96 | $helper->log('Define conditional formatting and set styles'); |
|
166 | 184 | ->setStyle($redStyle); |
167 | 185 | $conditionalStyles[] = $cellWizard->getConditional(); |
168 | 186 |
|
| 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 | + |
169 | 213 | $spreadsheet->getActiveSheet() |
170 | 214 | ->getStyle($cellWizard->getCellRange()) |
171 | 215 | ->setConditionalStyles($conditionalStyles); |
|
0 commit comments