@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | |
7 | 7 | class ConditionalStopIfTrue extends AbstractFunctional |
8 | 8 | { |
9 | - const |
|
9 | + const |
|
10 | 10 | COLOR_GREEN = 'FF99FF66', |
11 | 11 | COLOR_RED = 'FFFF5050' |
12 | 12 | ; |
@@ -25,50 +25,50 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function testConditionalStopIfTrue($format) |
27 | 27 | { |
28 | - $pCoordinate = 'A1:A3'; |
|
28 | + $pCoordinate = 'A1:A3'; |
|
29 | 29 | |
30 | - // if blank cell -> no styling |
|
31 | - $condition0 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); |
|
32 | - $condition0->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_EXPRESSION); |
|
33 | - $condition0->addCondition('LEN(TRIM(A1))=0'); |
|
34 | - $condition0->setStopIfTrue(true); // ! stop here |
|
30 | + // if blank cell -> no styling |
|
31 | + $condition0 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); |
|
32 | + $condition0->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_EXPRESSION); |
|
33 | + $condition0->addCondition('LEN(TRIM(A1))=0'); |
|
34 | + $condition0->setStopIfTrue(true); // ! stop here |
|
35 | 35 | |
36 | - // if value below 0.6 (matches also blank cells!) -> red background |
|
37 | - $condition1 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); |
|
38 | - $condition1->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS); |
|
39 | - $condition1->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN); |
|
40 | - $condition1->addCondition(0.6); |
|
41 | - $condition1->getStyle()->getFill() |
|
42 | - ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID) |
|
43 | - ->getEndColor()->setARGB(self::COLOR_RED); |
|
36 | + // if value below 0.6 (matches also blank cells!) -> red background |
|
37 | + $condition1 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); |
|
38 | + $condition1->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS); |
|
39 | + $condition1->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN); |
|
40 | + $condition1->addCondition(0.6); |
|
41 | + $condition1->getStyle()->getFill() |
|
42 | + ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID) |
|
43 | + ->getEndColor()->setARGB(self::COLOR_RED); |
|
44 | 44 | |
45 | - // if value above 0.6 -> green background |
|
46 | - $condition2 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); |
|
47 | - $condition2->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS); |
|
48 | - $condition2->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHAN); |
|
49 | - $condition2->addCondition(0.6); |
|
50 | - $condition2->getStyle()->getFill() |
|
51 | - ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID) |
|
52 | - ->getEndColor()->setARGB(self::COLOR_GREEN); |
|
45 | + // if value above 0.6 -> green background |
|
46 | + $condition2 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); |
|
47 | + $condition2->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS); |
|
48 | + $condition2->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHAN); |
|
49 | + $condition2->addCondition(0.6); |
|
50 | + $condition2->getStyle()->getFill() |
|
51 | + ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID) |
|
52 | + ->getEndColor()->setARGB(self::COLOR_GREEN); |
|
53 | 53 | |
54 | 54 | $spreadsheet = new Spreadsheet(); |
55 | 55 | $spreadsheet->getActiveSheet()->getCell('A1')->setValue(0.7); |
56 | - $spreadsheet->getActiveSheet()->getCell('A2')->setValue(''); |
|
57 | - $spreadsheet->getActiveSheet()->getCell('A3')->setValue(0.4); |
|
56 | + $spreadsheet->getActiveSheet()->getCell('A2')->setValue(''); |
|
57 | + $spreadsheet->getActiveSheet()->getCell('A3')->setValue(0.4); |
|
58 | 58 | |
59 | - // put all three conditions in sheet |
|
60 | - $conditionalStyles = []; |
|
61 | - array_push($conditionalStyles, $condition0); |
|
62 | - array_push($conditionalStyles, $condition1); |
|
63 | - array_push($conditionalStyles, $condition2); |
|
64 | - $spreadsheet->getActiveSheet()->setConditionalStyles($pCoordinate, $conditionalStyles); |
|
59 | + // put all three conditions in sheet |
|
60 | + $conditionalStyles = []; |
|
61 | + array_push($conditionalStyles, $condition0); |
|
62 | + array_push($conditionalStyles, $condition1); |
|
63 | + array_push($conditionalStyles, $condition2); |
|
64 | + $spreadsheet->getActiveSheet()->setConditionalStyles($pCoordinate, $conditionalStyles); |
|
65 | 65 | |
66 | 66 | $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format); |
67 | 67 | |
68 | - // see if we successfully written "StopIfTrue" |
|
69 | - $newConditionalStyles = $reloadedSpreadsheet->getActiveSheet()->getConditionalStyles($pCoordinate); |
|
70 | - self::assertTrue($newConditionalStyles[0]->getStopIfTrue(), 'StopIfTrue should be set (=true) on first condition'); |
|
71 | - self::assertFalse($newConditionalStyles[1]->getStopIfTrue(), 'StopIfTrue should not be set (=false) on second condition'); |
|
72 | - self::assertFalse($newConditionalStyles[2]->getStopIfTrue(), 'StopIfTrue should not be set (=false) on third condition'); |
|
68 | + // see if we successfully written "StopIfTrue" |
|
69 | + $newConditionalStyles = $reloadedSpreadsheet->getActiveSheet()->getConditionalStyles($pCoordinate); |
|
70 | + self::assertTrue($newConditionalStyles[0]->getStopIfTrue(), 'StopIfTrue should be set (=true) on first condition'); |
|
71 | + self::assertFalse($newConditionalStyles[1]->getStopIfTrue(), 'StopIfTrue should not be set (=false) on second condition'); |
|
72 | + self::assertFalse($newConditionalStyles[2]->getStopIfTrue(), 'StopIfTrue should not be set (=false) on third condition'); |
|
73 | 73 | } |
74 | 74 | } |