13
13
use PhpOffice \PhpSpreadsheet \Style \Border ;
14
14
use PhpOffice \PhpSpreadsheet \Style \Color ;
15
15
use PhpOffice \PhpSpreadsheet \Style \Conditional ;
16
- use PhpOffice \PhpSpreadsheet \Style \ConditionalFormatting \Wizard ;
17
16
use PhpOffice \PhpSpreadsheet \Style \Protection ;
18
17
use PhpOffice \PhpSpreadsheet \Worksheet \PageSetup ;
19
18
use PhpOffice \PhpSpreadsheet \Worksheet \SheetView ;
@@ -548,6 +547,8 @@ public function close(): void
548
547
549
548
private function writeConditionalFormatting (): void
550
549
{
550
+ $ conditionalFormulaHelper = new ConditionalHelper ($ this ->parser );
551
+
551
552
$ arrConditionalStyles = $ this ->phpSheet ->getConditionalStylesCollection ();
552
553
if (!empty ($ arrConditionalStyles )) {
553
554
$ arrConditional = [];
@@ -570,7 +571,7 @@ private function writeConditionalFormatting(): void
570
571
$ arrConditional [$ conditional ->getHashCode ()] = true ;
571
572
572
573
// Write CFRULE record
573
- $ this ->writeCFRule ($ conditional , $ cellCoordinate );
574
+ $ this ->writeCFRule ($ conditionalFormulaHelper , $ conditional , $ cellCoordinate );
574
575
}
575
576
}
576
577
}
@@ -2780,8 +2781,11 @@ private function writePageLayoutView(): void
2780
2781
/**
2781
2782
* Write CFRule Record.
2782
2783
*/
2783
- private function writeCFRule (Conditional $ conditional , string $ cellRange ): void
2784
- {
2784
+ private function writeCFRule (
2785
+ ConditionalHelper $ conditionalFormulaHelper ,
2786
+ Conditional $ conditional ,
2787
+ string $ cellRange
2788
+ ): void {
2785
2789
$ record = 0x01B1 ; // Record identifier
2786
2790
$ type = null ; // Type of the CF
2787
2791
$ operatorType = null ; // Comparison operator
@@ -2839,53 +2843,17 @@ private function writeCFRule(Conditional $conditional, string $cellRange): void
2839
2843
$ operand1 = null ;
2840
2844
$ operand2 = null ;
2841
2845
2842
- if ($ numConditions == 1 ) {
2843
- if (is_int ($ arrConditions [0 ]) || is_float ($ arrConditions [0 ])) {
2844
- $ szValue1 = ($ arrConditions [0 ] <= 65535 ? 3 : 0x0000 );
2845
- $ operand1 = pack ('Cv ' , 0x1E , $ arrConditions [0 ]);
2846
- } else {
2847
- try {
2848
- $ formula1 = Wizard \WizardAbstract::reverseAdjustCellRef ((string ) $ arrConditions [0 ], $ cellRange );
2849
- $ this ->parser ->parse ($ formula1 );
2850
- $ formula1 = $ this ->parser ->toReversePolish ();
2851
- $ szValue1 = strlen ($ formula1 );
2852
- } catch (PhpSpreadsheetException $ e ) {
2853
- var_dump ("PARSER EXCEPTION: {$ e ->getMessage ()}" );
2854
- $ formula1 = null ;
2855
- }
2856
- $ operand1 = $ formula1 ;
2857
- }
2858
- } elseif ($ numConditions == 2 && ($ conditional ->getOperatorType () == Conditional::OPERATOR_BETWEEN )) {
2859
- if (is_int ($ arrConditions [0 ]) || is_float ($ arrConditions [0 ])) {
2860
- $ szValue1 = ($ arrConditions [0 ] <= 65535 ? 3 : 0x0000 );
2861
- $ operand1 = pack ('Cv ' , 0x1E , $ arrConditions [0 ]);
2862
- } else {
2863
- try {
2864
- $ formula1 = Wizard \WizardAbstract::reverseAdjustCellRef ((string ) $ arrConditions [0 ], $ cellRange );
2865
- $ this ->parser ->parse ($ formula1 );
2866
- $ formula1 = $ this ->parser ->toReversePolish ();
2867
- $ szValue1 = strlen ($ formula1 );
2868
- } catch (PhpSpreadsheetException $ e ) {
2869
- var_dump ("PARSER EXCEPTION: {$ e ->getMessage ()}" );
2870
- $ formula1 = null ;
2871
- }
2872
- $ operand1 = $ formula1 ;
2873
- }
2874
- if (is_int ($ arrConditions [1 ]) || is_float ($ arrConditions [1 ])) {
2875
- $ szValue2 = ($ arrConditions [1 ] <= 65535 ? 3 : 0x0000 );
2876
- $ operand2 = pack ('Cv ' , 0x1E , $ arrConditions [1 ]);
2877
- } else {
2878
- try {
2879
- $ formula2 = Wizard \WizardAbstract::reverseAdjustCellRef ((string ) $ arrConditions [1 ], $ cellRange );
2880
- $ this ->parser ->parse ($ formula2 );
2881
- $ formula2 = $ this ->parser ->toReversePolish ();
2882
- $ szValue2 = strlen ($ formula2 );
2883
- } catch (PhpSpreadsheetException $ e ) {
2884
- var_dump ("PARSER EXCEPTION: {$ e ->getMessage ()}" );
2885
- $ formula2 = null ;
2886
- }
2887
- $ operand2 = $ formula2 ;
2888
- }
2846
+ if ($ numConditions === 1 ) {
2847
+ $ conditionalFormulaHelper ->processCondition ($ arrConditions [0 ], $ cellRange );
2848
+ $ szValue1 = $ conditionalFormulaHelper ->size ();
2849
+ $ operand1 = $ conditionalFormulaHelper ->tokens ();
2850
+ } elseif ($ numConditions === 2 && ($ conditional ->getOperatorType () === Conditional::OPERATOR_BETWEEN )) {
2851
+ $ conditionalFormulaHelper ->processCondition ($ arrConditions [0 ], $ cellRange );
2852
+ $ szValue1 = $ conditionalFormulaHelper ->size ();
2853
+ $ operand1 = $ conditionalFormulaHelper ->tokens ();
2854
+ $ conditionalFormulaHelper ->processCondition ($ arrConditions [1 ], $ cellRange );
2855
+ $ szValue2 = $ conditionalFormulaHelper ->size ();
2856
+ $ operand2 = $ conditionalFormulaHelper ->tokens ();
2889
2857
}
2890
2858
2891
2859
// $flags : Option flags
0 commit comments