Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function EXACT support #595

Merged
merged 5 commits into from
Jul 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
' ',
'',
],
];