From 75160b12821f7f4299cce7f0b69c83c1502ae071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Mon, 27 May 2024 13:08:29 +0200 Subject: 2024-02-19 upstream --- .../src/PhpSpreadsheet/Cell/DataValidator.php | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DataValidator.php (limited to 'vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DataValidator.php') diff --git a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DataValidator.php b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DataValidator.php new file mode 100644 index 0000000..5ba9e13 --- /dev/null +++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DataValidator.php @@ -0,0 +1,77 @@ +hasDataValidation()) { + return true; + } + + $cellValue = $cell->getValue(); + $dataValidation = $cell->getDataValidation(); + + if (!$dataValidation->getAllowBlank() && ($cellValue === null || $cellValue === '')) { + return false; + } + + // TODO: write check on all cases + switch ($dataValidation->getType()) { + case DataValidation::TYPE_LIST: + return $this->isValueInList($cell); + } + + return false; + } + + /** + * Does this cell contain valid value, based on list? + * + * @param Cell $cell Cell to check the value + * + * @return bool + */ + private function isValueInList(Cell $cell) + { + $cellValue = $cell->getValue(); + $dataValidation = $cell->getDataValidation(); + + $formula1 = $dataValidation->getFormula1(); + if (!empty($formula1)) { + // inline values list + if ($formula1[0] === '"') { + return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true); + } elseif (strpos($formula1, ':') > 0) { + // values list cells + $matchFormula = '=MATCH(' . $cell->getCoordinate() . ', ' . $formula1 . ', 0)'; + $calculation = Calculation::getInstance($cell->getWorksheet()->getParent()); + + try { + $result = $calculation->calculateFormula($matchFormula, $cell->getCoordinate(), $cell); + + return $result !== Functions::NA(); + } catch (Exception $ex) { + return false; + } + } + } + + return true; + } +} -- cgit v1.2.3