|
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; |
16 | 17 | use PhpOffice\PhpSpreadsheet\Style\Protection;
|
17 | 18 | use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
18 | 19 | use PhpOffice\PhpSpreadsheet\Worksheet\SheetView;
|
@@ -569,7 +570,7 @@ private function writeConditionalFormatting(): void
|
569 | 570 | $arrConditional[$conditional->getHashCode()] = true;
|
570 | 571 |
|
571 | 572 | // Write CFRULE record
|
572 |
| - $this->writeCFRule($conditional); |
| 573 | + $this->writeCFRule($conditional, $cellCoordinate); |
573 | 574 | }
|
574 | 575 | }
|
575 | 576 | }
|
@@ -2779,7 +2780,7 @@ private function writePageLayoutView(): void
|
2779 | 2780 | /**
|
2780 | 2781 | * Write CFRule Record.
|
2781 | 2782 | */
|
2782 |
| - private function writeCFRule(Conditional $conditional): void |
| 2783 | + private function writeCFRule(Conditional $conditional, string $cellRange): void |
2783 | 2784 | {
|
2784 | 2785 | $record = 0x01B1; // Record identifier
|
2785 | 2786 | $type = null; // Type of the CF
|
@@ -2832,21 +2833,59 @@ private function writeCFRule(Conditional $conditional): void
|
2832 | 2833 | // $szValue2 : size of the formula data for second value or formula
|
2833 | 2834 | $arrConditions = $conditional->getConditions();
|
2834 | 2835 | $numConditions = count($arrConditions);
|
| 2836 | + |
| 2837 | + $szValue1 = 0x0000; |
| 2838 | + $szValue2 = 0x0000; |
| 2839 | + $operand1 = null; |
| 2840 | + $operand2 = null; |
| 2841 | + |
2835 | 2842 | if ($numConditions == 1) {
|
2836 |
| - $szValue1 = ($arrConditions[0] <= 65535 ? 3 : 0x0000); |
2837 |
| - $szValue2 = 0x0000; |
2838 |
| - $operand1 = pack('Cv', 0x1E, $arrConditions[0]); |
2839 |
| - $operand2 = null; |
| 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 | + } |
2840 | 2858 | } elseif ($numConditions == 2 && ($conditional->getOperatorType() == Conditional::OPERATOR_BETWEEN)) {
|
2841 |
| - $szValue1 = ($arrConditions[0] <= 65535 ? 3 : 0x0000); |
2842 |
| - $szValue2 = ($arrConditions[1] <= 65535 ? 3 : 0x0000); |
2843 |
| - $operand1 = pack('Cv', 0x1E, $arrConditions[0]); |
2844 |
| - $operand2 = pack('Cv', 0x1E, $arrConditions[1]); |
2845 |
| - } else { |
2846 |
| - $szValue1 = 0x0000; |
2847 |
| - $szValue2 = 0x0000; |
2848 |
| - $operand1 = null; |
2849 |
| - $operand2 = null; |
| 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 | + } |
2850 | 2889 | }
|
2851 | 2890 |
|
2852 | 2891 | // $flags : Option flags
|
|
0 commit comments