PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.7.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.7.1
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Reader / Xlsx / ConditionalStyles.php

ConditionalStyles.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.7.1, at vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx/ConditionalStyles.php

93 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx;
4
5 use PhpOffice\PhpSpreadsheet\Style\Conditional;
6 use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
7
8 class ConditionalStyles
9 {
10 private $worksheet;
11
12 private $worksheetXml;
13
14 private $dxfs;
15
16 public function __construct(Worksheet $workSheet, \SimpleXMLElement $worksheetXml, array $dxfs = [])
17 {
18 $this->worksheet = $workSheet;
19 $this->worksheetXml = $worksheetXml;
20 $this->dxfs = $dxfs;
21 }
22
23 public function load()
24 {
25 $this->setConditionalStyles(
26 $this->worksheet,
27 $this->readConditionalStyles($this->worksheetXml)
28 );
29 }
30
31 private function readConditionalStyles($xmlSheet)
32 {
33 $conditionals = [];
34 foreach ($xmlSheet->conditionalFormatting as $conditional) {
35 foreach ($conditional->cfRule as $cfRule) {
36 if (((string) $cfRule['type'] == Conditional::CONDITION_NONE
37 || (string) $cfRule['type'] == Conditional::CONDITION_CELLIS
38 || (string) $cfRule['type'] == Conditional::CONDITION_CONTAINSTEXT
39 || (string) $cfRule['type'] == Conditional::CONDITION_EXPRESSION)
40 && isset($this->dxfs[(int) ($cfRule['dxfId'])])) {
41 $conditionals[(string) $conditional['sqref']][(int) ($cfRule['priority'])] = $cfRule;
42 }
43 }
44 }
45
46 return $conditionals;
47 }
48
49 private function setConditionalStyles(Worksheet $worksheet, array $conditionals)
50 {
51 foreach ($conditionals as $ref => $cfRules) {
52 ksort($cfRules);
53 $conditionalStyles = $this->readStyleRules($cfRules);
54
55 // Extract all cell references in $ref
56 $cellBlocks = explode(' ', str_replace('$', '', strtoupper($ref)));
57 foreach ($cellBlocks as $cellBlock) {
58 $worksheet->getStyle($cellBlock)->setConditionalStyles($conditionalStyles);
59 }
60 }
61 }
62
63 private function readStyleRules($cfRules)
64 {
65 $conditionalStyles = [];
66 foreach ($cfRules as $cfRule) {
67 $objConditional = new Conditional();
68 $objConditional->setConditionType((string) $cfRule['type']);
69 $objConditional->setOperatorType((string) $cfRule['operator']);
70
71 if ((string) $cfRule['text'] != '') {
72 $objConditional->setText((string) $cfRule['text']);
73 }
74
75 if (isset($cfRule['stopIfTrue']) && (int) $cfRule['stopIfTrue'] === 1) {
76 $objConditional->setStopIfTrue(true);
77 }
78
79 if (count($cfRule->formula) > 1) {
80 foreach ($cfRule->formula as $formula) {
81 $objConditional->addCondition((string) $formula);
82 }
83 } else {
84 $objConditional->addCondition((string) $cfRule->formula);
85 }
86 $objConditional->setStyle(clone $this->dxfs[(int) ($cfRule['dxfId'])]);
87 $conditionalStyles[] = $objConditional;
88 }
89
90 return $conditionalStyles;
91 }
92 }
93