diff --git a/CHANGELOG.md b/CHANGELOG.md index 58f117bc..a1a8d4dd 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 cd269be2..17e003e8 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -752,7 +752,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 f0e8a3c7..05553fbe 100644 --- a/src/PhpSpreadsheet/Calculation/TextData.php +++ b/src/PhpSpreadsheet/Calculation/TextData.php @@ -577,4 +577,22 @@ class TextData 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 91410829..c6e8ad84 100644 --- a/tests/PhpSpreadsheetTests/Calculation/TextDataTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/TextDataTest.php @@ -359,4 +359,28 @@ class TextDataTest extends TestCase { 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 00000000..f760a58f --- /dev/null +++ b/tests/data/Calculation/TextData/EXACT.php @@ -0,0 +1,39 @@ +