1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; |
6
|
|
|
|
7
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
8
|
|
|
|
9
|
|
|
class ConcatenateGnumericTest extends AllSetupTeardown |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Gnumeric, unlike Excel or LibreOffice, implements CONCATENATE like CONCAT. |
13
|
|
|
* |
14
|
|
|
* @dataProvider providerCONCAT |
15
|
|
|
*/ |
16
|
|
|
public function testCONCATENATE(mixed $expectedResult, mixed ...$args): void |
17
|
|
|
{ |
18
|
|
|
self::setGnumeric(); |
19
|
|
|
$this->mightHaveException($expectedResult); |
20
|
|
|
$sheet = $this->getSheet(); |
21
|
|
|
$finalArg = ''; |
22
|
|
|
$row = 0; |
23
|
|
|
foreach ($args as $arg) { |
24
|
|
|
++$row; |
25
|
|
|
$this->setCell("A$row", $arg); |
26
|
|
|
$finalArg = "A1:A$row"; |
27
|
|
|
} |
28
|
|
|
$this->setCell('B1', "=CONCATENATE($finalArg)"); |
29
|
|
|
$result = $sheet->getCell('B1')->getCalculatedValue(); |
30
|
|
|
self::assertEquals($expectedResult, $result); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public static function providerCONCAT(): array |
34
|
|
|
{ |
35
|
|
|
return require 'tests/data/Calculation/TextData/CONCAT.php'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testConcatWithIndexMatch(): void |
39
|
|
|
{ |
40
|
|
|
self::setGnumeric(); |
41
|
|
|
$spreadsheet = new Spreadsheet(); |
42
|
|
|
$sheet1 = $spreadsheet->getActiveSheet(); |
43
|
|
|
$sheet1->setTitle('Formula'); |
44
|
|
|
$sheet1->fromArray( |
45
|
|
|
[ |
46
|
|
|
['Number', 'Formula'], |
47
|
|
|
[52101293, '=CONCATENATE(INDEX(Lookup!B2, MATCH(A2, Lookup!A2, 0)))'], |
48
|
|
|
] |
49
|
|
|
); |
50
|
|
|
$sheet2 = $spreadsheet->createSheet(); |
51
|
|
|
$sheet2->setTitle('Lookup'); |
52
|
|
|
$sheet2->fromArray( |
53
|
|
|
[ |
54
|
|
|
['Lookup', 'Match'], |
55
|
|
|
[52101293, 'PHP'], |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
self::assertSame('PHP', $sheet1->getCell('B2')->getCalculatedValue()); |
59
|
|
|
$spreadsheet->disconnectWorksheets(); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|