Skip to content

Commit

Permalink
Function EXACT(arg1, arg2) support (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandsusans authored and PowerKiKi committed Jul 15, 2018
1 parent 043327b commit eb31899
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ class Calculation
],
'EXACT' => [
'category' => Category::CATEGORY_TEXT_AND_DATA,
'functionCall' => [Functions::class, 'DUMMY'],
'functionCall' => [TextData::class, 'EXACT'],
'argumentCount' => '2',
],
'EXP' => [
Expand Down
18 changes: 18 additions & 0 deletions src/PhpSpreadsheet/Calculation/TextData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
24 changes: 24 additions & 0 deletions tests/PhpSpreadsheetTests/Calculation/TextDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
39 changes: 39 additions & 0 deletions tests/data/Calculation/TextData/EXACT.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

return [
[
true,
'',
'',
],
[
true,
'1000',
1000,
],
[
true,
1000,
'1000',
],
[
true,
'Abč',
'Abč',
],
[
false,
'abč',
'Abč',
],
[
false,
'10.010',
10.01,
],
[
false,
' ',
'',
],
];

0 comments on commit eb31899

Please sign in to comment.