diff --git a/CHANGELOG.md b/CHANGELOG.md index 58f117bc71..a1a8d4ddee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added +- Add excel function EXACT(value1, value2) support - Support workbook view attributes for Xlsx format - [#523](https://github.com/PHPOffice/PhpSpreadsheet/issues/523) ### Fixed diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index 0dad8da806..49243ffce2 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -755,7 +755,7 @@ class Calculation ], 'EXACT' => [ 'category' => Category::CATEGORY_TEXT_AND_DATA, - 'functionCall' => [Functions::class, 'DUMMY'], + 'functionCall' => [TextData::class, 'EXACT'], 'argumentCount' => '2', ], 'EXP' => [ diff --git a/src/PhpSpreadsheet/Calculation/TextData.php b/src/PhpSpreadsheet/Calculation/TextData.php index f0e8a3c7fc..05553fbe42 100644 --- a/src/PhpSpreadsheet/Calculation/TextData.php +++ b/src/PhpSpreadsheet/Calculation/TextData.php @@ -577,4 +577,22 @@ public static function VALUE($value = '') return (float) $value; } + + /** + * Compares two text strings and returns TRUE if they are exactly the same, FALSE otherwise. + * EXACT is case-sensitive but ignores formatting differences. + * Use EXACT to test text being entered into a document. + * + * @param $value1 + * @param $value2 + * + * @return bool + */ + public static function EXACT($value1, $value2) + { + $value1 = Functions::flattenSingleValue($value1); + $value2 = Functions::flattenSingleValue($value2); + + return (string) $value2 === (string) $value1; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/TextDataTest.php b/tests/PhpSpreadsheetTests/Calculation/TextDataTest.php index 9141082965..c6e8ad8475 100644 --- a/tests/PhpSpreadsheetTests/Calculation/TextDataTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/TextDataTest.php @@ -359,4 +359,28 @@ public function providerVALUE() { return require 'data/Calculation/TextData/VALUE.php'; } + + /** + * @dataProvider providerEXACT + * + * @param mixed $expectedResult + * @param array $args + */ + public function testEXACT($expectedResult, ...$args) + { + StringHelper::setDecimalSeparator('.'); + StringHelper::setThousandsSeparator(' '); + StringHelper::setCurrencyCode('$'); + + $result = TextData::EXACT(...$args); + self::assertSame($expectedResult, $result, null); + } + + /** + * @return array + */ + public function providerEXACT() + { + return require 'data/Calculation/TextData/EXACT.php'; + } } diff --git a/tests/data/Calculation/TextData/EXACT.php b/tests/data/Calculation/TextData/EXACT.php new file mode 100644 index 0000000000..f760a58fbc --- /dev/null +++ b/tests/data/Calculation/TextData/EXACT.php @@ -0,0 +1,39 @@ +