PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.9.4
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.9.4
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 / Cell / DataValidator.php

DataValidator.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.9.4, at vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DataValidator.php

78 lines 2.1 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\Cell;
4
5 use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
6 use PhpOffice\PhpSpreadsheet\Calculation\Functions;
7 use PhpOffice\PhpSpreadsheet\Exception;
8
9 /**
10 * Validate a cell value according to its validation rules.
11 */
12 class DataValidator
13 {
14 /**
15 * Does this cell contain valid value?
16 *
17 * @param Cell $cell Cell to check the value
18 *
19 * @return bool
20 */
21 public function isValid(Cell $cell)
22 {
23 if (!$cell->hasDataValidation()) {
24 return true;
25 }
26
27 $cellValue = $cell->getValue();
28 $dataValidation = $cell->getDataValidation();
29
30 if (!$dataValidation->getAllowBlank() && ($cellValue === null || $cellValue === '')) {
31 return false;
32 }
33
34 // TODO: write check on all cases
35 switch ($dataValidation->getType()) {
36 case DataValidation::TYPE_LIST:
37 return $this->isValueInList($cell);
38 }
39
40 return false;
41 }
42
43 /**
44 * Does this cell contain valid value, based on list?
45 *
46 * @param Cell $cell Cell to check the value
47 *
48 * @return bool
49 */
50 private function isValueInList(Cell $cell)
51 {
52 $cellValue = $cell->getValue();
53 $dataValidation = $cell->getDataValidation();
54
55 $formula1 = $dataValidation->getFormula1();
56 if (!empty($formula1)) {
57 // inline values list
58 if ($formula1[0] === '"') {
59 return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true);
60 } elseif (strpos($formula1, ':') > 0) {
61 // values list cells
62 $matchFormula = '=MATCH(' . $cell->getCoordinate() . ', ' . $formula1 . ', 0)';
63 $calculation = Calculation::getInstance($cell->getWorksheet()->getParent());
64
65 try {
66 $result = $calculation->calculateFormula($matchFormula, $cell->getCoordinate(), $cell);
67
68 return $result !== Functions::NA();
69 } catch (Exception $ex) {
70 return false;
71 }
72 }
73 }
74
75 return true;
76 }
77 }
78