From 07ac3e889c66e61e940672bad0ae739c3ce93a05 Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Fri, 20 Oct 2017 10:38:37 +0300 Subject: [PATCH 01/12] Cell->hasValidValue() - test value on list validation --- src/PhpSpreadsheet/Cell.php | 48 +++++++++++++++++++++++++- tests/PhpSpreadsheetTests/CellTest.php | 37 ++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Cell.php b/src/PhpSpreadsheet/Cell.php index 235ec73df4..75bbcb226d 100644 --- a/src/PhpSpreadsheet/Cell.php +++ b/src/PhpSpreadsheet/Cell.php @@ -410,7 +410,53 @@ public function setDataValidation(Cell\DataValidation $pDataValidation = null) } /** - * Does this cell contain a Hyperlink? + * Does this cell contain valid value? + * + * @return bool + */ + public function hasValidValue() + { + if (!$this->hasDataValidation()) { + return true; + } + + $cellValue = $this->getValue(); + $cellValidation = $this->getDataValidation(); + + if (!$cellValidation->getAllowBlank() && (is_null($cellValue) || $cellValue == "")) + return false; + + // TODO: write check on all cases + switch ($cellValidation->getType()) { + case Cell\DataValidation::TYPE_LIST: + $formula1 = $cellValidation->getFormula1(); + if (empty($formula1)) + break; + + if ($formula1[0] == '"') { // inline values list + return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true); + + } else if (strpos($formula1, ':') > 0) { // values list cells + $match_formula = '=MATCH('.$this->getCoordinate().','.$formula1.',0)'; + + try { + $result = Calculation::getInstance( + $this->getWorksheet()->getParent() + )->calculateFormula($match_formula, $this->getCoordinate(), $this); + + return ($result != "#N/A"); + } catch (Exception $ex) { + return false; + } + } + break; + } + + return true; + } + + /** + * Does this cell contain a Hyperlink? * * @throws Exception * diff --git a/tests/PhpSpreadsheetTests/CellTest.php b/tests/PhpSpreadsheetTests/CellTest.php index 9708981ccf..ee4aff2e97 100644 --- a/tests/PhpSpreadsheetTests/CellTest.php +++ b/tests/PhpSpreadsheetTests/CellTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Exception; use PHPUnit_Framework_TestCase; @@ -323,4 +324,40 @@ public function providerMergeRangesInCollection() { return require 'data/CellMergeRangesInCollection.php'; } + + public function testHasValidValue() + { + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + $testCell = $sheet->getCell('A1'); + + $validation = $testCell->getDataValidation(); + $validation->setType( \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST ); + + // blank value + $testCell->setValue(""); + $validation->setAllowBlank(true); + self::assertEquals(true, $testCell->hasValidValue(), "cell can be empty"); + $validation->setAllowBlank(false); + self::assertEquals(false, $testCell->hasValidValue(), "cell can not be empty"); + + // inline list + $validation->setFormula1('"yes,no"'); + $testCell->setValue("foo"); + self::assertEquals(false, $testCell->hasValidValue(), "cell value ('foo') is not allowed"); + $testCell->setValue("yes"); + self::assertEquals(true, $testCell->hasValidValue(), "cell value ('yes') has to be allowed"); + + // list from cells + $sheet->getCell('B1')->setValue(5); + $sheet->getCell('B2')->setValue(6); + $sheet->getCell('B3')->setValue(7); + $testCell = $sheet->getCell('A1'); // redefine $testCell, because it has broken coordinates after using other cells + $validation->setFormula1('B1:B3'); + $testCell->setValue("10"); + self::assertEquals(false, $testCell->hasValidValue(), "cell value ('10') is not allowed"); + $testCell = $sheet->getCell('A1'); // redefine $testCell, because it has broken coordinates after using other cells + $testCell->setValue("5"); + self::assertEquals(true, $testCell->hasValidValue(), "cell value ('5') has to be allowed"); + } } From db2ff602aed5237511262035d1cb83b76247db08 Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Fri, 20 Oct 2017 10:51:25 +0300 Subject: [PATCH 02/12] syntax fix --- src/PhpSpreadsheet/Cell.php | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/PhpSpreadsheet/Cell.php b/src/PhpSpreadsheet/Cell.php index 75bbcb226d..4e2a410a26 100644 --- a/src/PhpSpreadsheet/Cell.php +++ b/src/PhpSpreadsheet/Cell.php @@ -423,32 +423,31 @@ public function hasValidValue() $cellValue = $this->getValue(); $cellValidation = $this->getDataValidation(); - if (!$cellValidation->getAllowBlank() && (is_null($cellValue) || $cellValue == "")) + if (!$cellValidation->getAllowBlank() && ($cellValue === null || $cellValue == "")) { return false; + } // TODO: write check on all cases switch ($cellValidation->getType()) { case Cell\DataValidation::TYPE_LIST: $formula1 = $cellValidation->getFormula1(); - if (empty($formula1)) - break; - - if ($formula1[0] == '"') { // inline values list - return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true); - - } else if (strpos($formula1, ':') > 0) { // values list cells - $match_formula = '=MATCH('.$this->getCoordinate().','.$formula1.',0)'; - - try { - $result = Calculation::getInstance( - $this->getWorksheet()->getParent() - )->calculateFormula($match_formula, $this->getCoordinate(), $this); - - return ($result != "#N/A"); - } catch (Exception $ex) { - return false; + if (!empty($formula1)) { + if ($formula1[0] == '"') { // inline values list + return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true); + + } elseif (strpos($formula1, ':') > 0) { // values list cells + $match_formula = '=MATCH('.$this->getCoordinate().','.$formula1.',0)'; + try { + $result = Calculation::getInstance( + $this->getWorksheet()->getParent() + )->calculateFormula($match_formula, $this->getCoordinate(), $this); + return $result != "#N/A"; + } catch (Exception $ex) { + return false; + } } } + break; } From 16a2525d030ea8f84f6db72c36a32a9dddc26a8b Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Fri, 20 Oct 2017 11:00:13 +0300 Subject: [PATCH 03/12] syntax fix --- src/PhpSpreadsheet/Cell.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PhpSpreadsheet/Cell.php b/src/PhpSpreadsheet/Cell.php index 4e2a410a26..99136584e8 100644 --- a/src/PhpSpreadsheet/Cell.php +++ b/src/PhpSpreadsheet/Cell.php @@ -423,7 +423,7 @@ public function hasValidValue() $cellValue = $this->getValue(); $cellValidation = $this->getDataValidation(); - if (!$cellValidation->getAllowBlank() && ($cellValue === null || $cellValue == "")) { + if (!$cellValidation->getAllowBlank() && ($cellValue === null || $cellValue == '')) { return false; } @@ -436,11 +436,12 @@ public function hasValidValue() return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true); } elseif (strpos($formula1, ':') > 0) { // values list cells - $match_formula = '=MATCH('.$this->getCoordinate().','.$formula1.',0)'; + $match_formula = '=MATCH(' . $this->getCoordinate() . ',' . $formula1 . ',0)'; try { $result = Calculation::getInstance( $this->getWorksheet()->getParent() )->calculateFormula($match_formula, $this->getCoordinate(), $this); + return $result != "#N/A"; } catch (Exception $ex) { return false; From e72958685f08f02367db09dd63290b4d5f531f49 Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Fri, 20 Oct 2017 11:09:32 +0300 Subject: [PATCH 04/12] syntax fix --- src/PhpSpreadsheet/Cell.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpSpreadsheet/Cell.php b/src/PhpSpreadsheet/Cell.php index 99136584e8..08e63a3b30 100644 --- a/src/PhpSpreadsheet/Cell.php +++ b/src/PhpSpreadsheet/Cell.php @@ -441,8 +441,8 @@ public function hasValidValue() $result = Calculation::getInstance( $this->getWorksheet()->getParent() )->calculateFormula($match_formula, $this->getCoordinate(), $this); - - return $result != "#N/A"; + + return $result != '#N/A'; } catch (Exception $ex) { return false; } From 7ce2366432d8f62be58c252ea154c199cbad5c07 Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Fri, 20 Oct 2017 11:17:01 +0300 Subject: [PATCH 05/12] syntax fix --- tests/PhpSpreadsheetTests/CellTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/PhpSpreadsheetTests/CellTest.php b/tests/PhpSpreadsheetTests/CellTest.php index ee4aff2e97..5d0d373765 100644 --- a/tests/PhpSpreadsheetTests/CellTest.php +++ b/tests/PhpSpreadsheetTests/CellTest.php @@ -2,9 +2,9 @@ namespace PhpOffice\PhpSpreadsheetTests; -use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Exception; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit_Framework_TestCase; class CellTest extends PHPUnit_Framework_TestCase @@ -332,20 +332,20 @@ public function testHasValidValue() $testCell = $sheet->getCell('A1'); $validation = $testCell->getDataValidation(); - $validation->setType( \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST ); + $validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST); // blank value - $testCell->setValue(""); + $testCell->setValue(''); $validation->setAllowBlank(true); - self::assertEquals(true, $testCell->hasValidValue(), "cell can be empty"); + self::assertEquals(true, $testCell->hasValidValue(), 'cell can be empty'); $validation->setAllowBlank(false); - self::assertEquals(false, $testCell->hasValidValue(), "cell can not be empty"); + self::assertEquals(false, $testCell->hasValidValue(), 'cell can not be empty'); // inline list $validation->setFormula1('"yes,no"'); - $testCell->setValue("foo"); + $testCell->setValue('foo'); self::assertEquals(false, $testCell->hasValidValue(), "cell value ('foo') is not allowed"); - $testCell->setValue("yes"); + $testCell->setValue('yes'); self::assertEquals(true, $testCell->hasValidValue(), "cell value ('yes') has to be allowed"); // list from cells @@ -354,10 +354,10 @@ public function testHasValidValue() $sheet->getCell('B3')->setValue(7); $testCell = $sheet->getCell('A1'); // redefine $testCell, because it has broken coordinates after using other cells $validation->setFormula1('B1:B3'); - $testCell->setValue("10"); + $testCell->setValue('10'); self::assertEquals(false, $testCell->hasValidValue(), "cell value ('10') is not allowed"); $testCell = $sheet->getCell('A1'); // redefine $testCell, because it has broken coordinates after using other cells - $testCell->setValue("5"); + $testCell->setValue('5'); self::assertEquals(true, $testCell->hasValidValue(), "cell value ('5') has to be allowed"); } } From a6e2c10b9ffc23f2bba97b8769853715014e68fd Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Fri, 20 Oct 2017 11:23:27 +0300 Subject: [PATCH 06/12] syntax fix --- src/PhpSpreadsheet/Cell.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Cell.php b/src/PhpSpreadsheet/Cell.php index 08e63a3b30..9f2c154cd8 100644 --- a/src/PhpSpreadsheet/Cell.php +++ b/src/PhpSpreadsheet/Cell.php @@ -434,9 +434,9 @@ public function hasValidValue() if (!empty($formula1)) { if ($formula1[0] == '"') { // inline values list return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true); - } elseif (strpos($formula1, ':') > 0) { // values list cells $match_formula = '=MATCH(' . $this->getCoordinate() . ',' . $formula1 . ',0)'; + try { $result = Calculation::getInstance( $this->getWorksheet()->getParent() From bc26ee53761e8957e1830e3fa81dcc4fe8f9afa1 Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Mon, 23 Oct 2017 14:35:39 +0300 Subject: [PATCH 07/12] move validator code to DataValidator class --- src/PhpSpreadsheet/Cell.php | 34 +-------------- src/PhpSpreadsheet/Cell/DataValidator.php | 53 +++++++++++++++++++++++ 2 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 src/PhpSpreadsheet/Cell/DataValidator.php diff --git a/src/PhpSpreadsheet/Cell.php b/src/PhpSpreadsheet/Cell.php index 9f2c154cd8..1140f2cb7c 100644 --- a/src/PhpSpreadsheet/Cell.php +++ b/src/PhpSpreadsheet/Cell.php @@ -420,39 +420,7 @@ public function hasValidValue() return true; } - $cellValue = $this->getValue(); - $cellValidation = $this->getDataValidation(); - - if (!$cellValidation->getAllowBlank() && ($cellValue === null || $cellValue == '')) { - return false; - } - - // TODO: write check on all cases - switch ($cellValidation->getType()) { - case Cell\DataValidation::TYPE_LIST: - $formula1 = $cellValidation->getFormula1(); - if (!empty($formula1)) { - if ($formula1[0] == '"') { // inline values list - return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true); - } elseif (strpos($formula1, ':') > 0) { // values list cells - $match_formula = '=MATCH(' . $this->getCoordinate() . ',' . $formula1 . ',0)'; - - try { - $result = Calculation::getInstance( - $this->getWorksheet()->getParent() - )->calculateFormula($match_formula, $this->getCoordinate(), $this); - - return $result != '#N/A'; - } catch (Exception $ex) { - return false; - } - } - } - - break; - } - - return true; + return (new Cell\DataValidator())->isValidCellValue($this); } /** diff --git a/src/PhpSpreadsheet/Cell/DataValidator.php b/src/PhpSpreadsheet/Cell/DataValidator.php new file mode 100644 index 0000000000..60874da4f1 --- /dev/null +++ b/src/PhpSpreadsheet/Cell/DataValidator.php @@ -0,0 +1,53 @@ +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: + $formula1 = $dataValidation->getFormula1(); + if (!empty($formula1)) { + if ($formula1[0] == '"') { // inline values list + return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true); + } elseif (strpos($formula1, ':') > 0) { // values list cells + $match_formula = '=MATCH(' . $cell->getCoordinate() . ',' . $formula1 . ',0)'; + + try { + $result = Calculation::getInstance( + $cell->getWorksheet()->getParent() + )->calculateFormula($match_formula, $cell->getCoordinate(), $cell); + + return $result !== Functions::NA(); + } catch (Exception $ex) { + return false; + } + } + } + + break; + } + + return true; + } +} From 6c26b3a0e57cd3008efa1dcf47879d8b0f21dd6d Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Mon, 23 Oct 2017 14:41:37 +0300 Subject: [PATCH 08/12] spaces fix --- src/PhpSpreadsheet/Cell/DataValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Cell/DataValidator.php b/src/PhpSpreadsheet/Cell/DataValidator.php index 60874da4f1..9b8925902a 100644 --- a/src/PhpSpreadsheet/Cell/DataValidator.php +++ b/src/PhpSpreadsheet/Cell/DataValidator.php @@ -9,7 +9,7 @@ class DataValidator { /** * Does this cell contain valid value? - * + * * @param Cell $cell Cell to check the value * * @return bool From bcf92d9b9d300b1d428d267477afd22c4924fde5 Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Mon, 23 Oct 2017 15:24:06 +0300 Subject: [PATCH 09/12] DataValidator -> CellDataValidator + extract isValueInList() --- src/PhpSpreadsheet/Cell.php | 2 +- src/PhpSpreadsheet/Cell/CellDataValidator.php | 62 +++++++++++++++++++ src/PhpSpreadsheet/Cell/DataValidator.php | 53 ---------------- 3 files changed, 63 insertions(+), 54 deletions(-) create mode 100644 src/PhpSpreadsheet/Cell/CellDataValidator.php delete mode 100644 src/PhpSpreadsheet/Cell/DataValidator.php diff --git a/src/PhpSpreadsheet/Cell.php b/src/PhpSpreadsheet/Cell.php index 1140f2cb7c..93491d9ee5 100644 --- a/src/PhpSpreadsheet/Cell.php +++ b/src/PhpSpreadsheet/Cell.php @@ -420,7 +420,7 @@ public function hasValidValue() return true; } - return (new Cell\DataValidator())->isValidCellValue($this); + return (new Cell\CellDataValidator())->isValid($this); } /** diff --git a/src/PhpSpreadsheet/Cell/CellDataValidator.php b/src/PhpSpreadsheet/Cell/CellDataValidator.php new file mode 100644 index 0000000000..e8a9eebdf1 --- /dev/null +++ b/src/PhpSpreadsheet/Cell/CellDataValidator.php @@ -0,0 +1,62 @@ +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 true; + } + + private function isValueInList(Cell $cell) + { + $cellValue = $cell->getValue(); + $dataValidation = $cell->getDataValidation(); + + $formula1 = $dataValidation->getFormula1(); + if (!empty($formula1)) { + if ($formula1[0] === '"') { // inline values list + return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true); + } elseif (strpos($formula1, ':') > 0) { // values list cells + $match_formula = '=MATCH(' . $cell->getCoordinate() . ',' . $formula1 . ',0)'; + + try { + $result = Calculation::getInstance( + $cell->getWorksheet()->getParent() + )->calculateFormula($match_formula, $cell->getCoordinate(), $cell); + + return $result !== Functions::NA(); + } catch (Exception $ex) { + return false; + } + } + } + + return true; + } +} diff --git a/src/PhpSpreadsheet/Cell/DataValidator.php b/src/PhpSpreadsheet/Cell/DataValidator.php deleted file mode 100644 index 9b8925902a..0000000000 --- a/src/PhpSpreadsheet/Cell/DataValidator.php +++ /dev/null @@ -1,53 +0,0 @@ -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: - $formula1 = $dataValidation->getFormula1(); - if (!empty($formula1)) { - if ($formula1[0] == '"') { // inline values list - return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true); - } elseif (strpos($formula1, ':') > 0) { // values list cells - $match_formula = '=MATCH(' . $cell->getCoordinate() . ',' . $formula1 . ',0)'; - - try { - $result = Calculation::getInstance( - $cell->getWorksheet()->getParent() - )->calculateFormula($match_formula, $cell->getCoordinate(), $cell); - - return $result !== Functions::NA(); - } catch (Exception $ex) { - return false; - } - } - } - - break; - } - - return true; - } -} From 0bb7ec6c86fe8f2e2b7f0a1a78027a5f2ab3d023 Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Mon, 23 Oct 2017 15:35:34 +0300 Subject: [PATCH 10/12] comment to isValueInList() --- src/PhpSpreadsheet/Cell/CellDataValidator.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/PhpSpreadsheet/Cell/CellDataValidator.php b/src/PhpSpreadsheet/Cell/CellDataValidator.php index e8a9eebdf1..b94ec0c056 100644 --- a/src/PhpSpreadsheet/Cell/CellDataValidator.php +++ b/src/PhpSpreadsheet/Cell/CellDataValidator.php @@ -33,6 +33,13 @@ public function isValid(Cell $cell) return true; } + /** + * 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(); From 4f2d1b1161e75445e26cbf352e8c30253105c538 Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Mon, 30 Oct 2017 10:01:30 +0200 Subject: [PATCH 11/12] move part of validation to isValid() --- src/PhpSpreadsheet/Cell.php | 4 ---- src/PhpSpreadsheet/Cell/CellDataValidator.php | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PhpSpreadsheet/Cell.php b/src/PhpSpreadsheet/Cell.php index 93491d9ee5..0d8d23dff6 100644 --- a/src/PhpSpreadsheet/Cell.php +++ b/src/PhpSpreadsheet/Cell.php @@ -416,10 +416,6 @@ public function setDataValidation(Cell\DataValidation $pDataValidation = null) */ public function hasValidValue() { - if (!$this->hasDataValidation()) { - return true; - } - return (new Cell\CellDataValidator())->isValid($this); } diff --git a/src/PhpSpreadsheet/Cell/CellDataValidator.php b/src/PhpSpreadsheet/Cell/CellDataValidator.php index b94ec0c056..c5ac7d49e3 100644 --- a/src/PhpSpreadsheet/Cell/CellDataValidator.php +++ b/src/PhpSpreadsheet/Cell/CellDataValidator.php @@ -17,6 +17,10 @@ class CellDataValidator */ public function isValid(Cell $cell) { + if (!$cell->hasDataValidation()) { + return true; + } + $cellValue = $cell->getValue(); $dataValidation = $cell->getDataValidation(); From 451f577b89450eb5a582305cdc757a63801e4f70 Mon Sep 17 00:00:00 2001 From: Maxim Bulygin Date: Mon, 30 Oct 2017 13:26:48 +0200 Subject: [PATCH 12/12] fixes after merge --- src/PhpSpreadsheet/Cell/Cell.php | 2 +- src/PhpSpreadsheet/Cell/CellDataValidator.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/Cell/Cell.php b/src/PhpSpreadsheet/Cell/Cell.php index 3de6a8fbf9..9fa84f08ad 100644 --- a/src/PhpSpreadsheet/Cell/Cell.php +++ b/src/PhpSpreadsheet/Cell/Cell.php @@ -421,7 +421,7 @@ public function setDataValidation(DataValidation $pDataValidation = null) */ public function hasValidValue() { - return (new Cell\CellDataValidator())->isValid($this); + return (new CellDataValidator())->isValid($this); } /** diff --git a/src/PhpSpreadsheet/Cell/CellDataValidator.php b/src/PhpSpreadsheet/Cell/CellDataValidator.php index c5ac7d49e3..e93a749ea5 100644 --- a/src/PhpSpreadsheet/Cell/CellDataValidator.php +++ b/src/PhpSpreadsheet/Cell/CellDataValidator.php @@ -4,7 +4,7 @@ use PhpOffice\PhpSpreadsheet\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Exception; class CellDataValidator { @@ -57,7 +57,7 @@ private function isValueInList(Cell $cell) $match_formula = '=MATCH(' . $cell->getCoordinate() . ',' . $formula1 . ',0)'; try { - $result = Calculation::getInstance( + $result = Calculation\Calculation::getInstance( $cell->getWorksheet()->getParent() )->calculateFormula($match_formula, $cell->getCoordinate(), $cell);