1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Exception; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Conditional; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard\WizardInterface; |
8
|
|
|
|
9
|
|
|
class Wizard |
10
|
|
|
{ |
11
|
|
|
public const CELL_VALUE = 'cellValue'; |
12
|
|
|
public const TEXT_VALUE = 'textValue'; |
13
|
|
|
public const BLANKS = Conditional::CONDITION_CONTAINSBLANKS; |
14
|
|
|
public const NOT_BLANKS = Conditional::CONDITION_NOTCONTAINSBLANKS; |
15
|
|
|
public const ERRORS = Conditional::CONDITION_CONTAINSERRORS; |
16
|
|
|
public const NOT_ERRORS = Conditional::CONDITION_NOTCONTAINSERRORS; |
17
|
|
|
public const EXPRESSION = Conditional::CONDITION_EXPRESSION; |
18
|
|
|
public const FORMULA = Conditional::CONDITION_EXPRESSION; |
19
|
|
|
public const DATES_OCCURRING = 'DateValue'; |
20
|
|
|
public const DUPLICATES = Conditional::CONDITION_DUPLICATES; |
21
|
|
|
public const UNIQUE = Conditional::CONDITION_UNIQUE; |
22
|
|
|
|
23
|
|
|
public const VALUE_TYPE_LITERAL = 'value'; |
24
|
|
|
public const VALUE_TYPE_CELL = 'cell'; |
25
|
|
|
public const VALUE_TYPE_FORMULA = 'formula'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $cellRange; |
31
|
|
|
|
32
|
97 |
|
public function __construct(string $cellRange) |
33
|
|
|
{ |
34
|
97 |
|
$this->cellRange = $cellRange; |
35
|
|
|
} |
36
|
|
|
|
37
|
79 |
|
public function newRule(string $ruleType): WizardInterface |
38
|
|
|
{ |
39
|
|
|
switch ($ruleType) { |
40
|
79 |
|
case self::CELL_VALUE: |
41
|
41 |
|
return new Wizard\CellValue($this->cellRange); |
42
|
39 |
|
case self::TEXT_VALUE: |
43
|
7 |
|
return new Wizard\TextValue($this->cellRange); |
44
|
32 |
|
case self::BLANKS: |
45
|
4 |
|
return new Wizard\Blanks($this->cellRange, true); |
46
|
28 |
|
case self::NOT_BLANKS: |
47
|
3 |
|
return new Wizard\Blanks($this->cellRange, false); |
48
|
25 |
|
case self::ERRORS: |
49
|
4 |
|
return new Wizard\Errors($this->cellRange, true); |
50
|
21 |
|
case self::NOT_ERRORS: |
51
|
3 |
|
return new Wizard\Errors($this->cellRange, false); |
52
|
18 |
|
case self::EXPRESSION: |
53
|
12 |
|
case self::FORMULA: |
54
|
6 |
|
return new Wizard\Expression($this->cellRange); |
55
|
12 |
|
case self::DATES_OCCURRING: |
56
|
6 |
|
return new Wizard\DateValue($this->cellRange); |
57
|
6 |
|
case self::DUPLICATES: |
58
|
3 |
|
return new Wizard\Duplicates($this->cellRange, false); |
59
|
3 |
|
case self::UNIQUE: |
60
|
2 |
|
return new Wizard\Duplicates($this->cellRange, true); |
61
|
|
|
default: |
62
|
1 |
|
throw new Exception('No wizard exists for this CF rule type'); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
62 |
|
public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface |
67
|
|
|
{ |
68
|
62 |
|
$conditionalType = $conditional->getConditionType(); |
69
|
|
|
|
70
|
|
|
switch ($conditionalType) { |
71
|
|
|
case Conditional::CONDITION_CELLIS: |
72
|
29 |
|
return Wizard\CellValue::fromConditional($conditional, $cellRange); |
73
|
|
|
case Conditional::CONDITION_CONTAINSTEXT: |
74
|
|
|
case Conditional::CONDITION_NOTCONTAINSTEXT: |
75
|
|
|
case Conditional::CONDITION_BEGINSWITH: |
76
|
|
|
case Conditional::CONDITION_ENDSWITH: |
77
|
9 |
|
return Wizard\TextValue::fromConditional($conditional, $cellRange); |
78
|
|
|
case Conditional::CONDITION_CONTAINSBLANKS: |
79
|
|
|
case Conditional::CONDITION_NOTCONTAINSBLANKS: |
80
|
5 |
|
return Wizard\Blanks::fromConditional($conditional, $cellRange); |
81
|
|
|
case Conditional::CONDITION_CONTAINSERRORS: |
82
|
|
|
case Conditional::CONDITION_NOTCONTAINSERRORS: |
83
|
5 |
|
return Wizard\Errors::fromConditional($conditional, $cellRange); |
84
|
|
|
case Conditional::CONDITION_TIMEPERIOD: |
85
|
5 |
|
return Wizard\DateValue::fromConditional($conditional, $cellRange); |
86
|
|
|
case Conditional::CONDITION_EXPRESSION: |
87
|
3 |
|
return Wizard\Expression::fromConditional($conditional, $cellRange); |
88
|
|
|
case Conditional::CONDITION_DUPLICATES: |
89
|
|
|
case Conditional::CONDITION_UNIQUE: |
90
|
5 |
|
return Wizard\Duplicates::fromConditional($conditional, $cellRange); |
91
|
|
|
default: |
92
|
1 |
|
throw new Exception('No wizard exists for this CF rule type'); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|