1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
class FormulaAsStringTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @dataProvider providerFunctionsAsString |
12
|
|
|
* |
13
|
|
|
* @param mixed $expectedResult |
14
|
|
|
* @param string $formula |
15
|
|
|
*/ |
16
|
|
|
public function testFunctionsAsString($expectedResult, $formula) |
17
|
|
|
{ |
18
|
|
|
$spreadsheet = new Spreadsheet(); |
19
|
|
|
$workSheet = $spreadsheet->getActiveSheet(); |
20
|
|
|
$workSheet->setCellValue('A1', 10); |
21
|
|
|
$workSheet->setCellValue('A2', 20); |
22
|
|
|
$workSheet->setCellValue('A3', 30); |
23
|
|
|
$workSheet->setCellValue('A4', 40); |
24
|
|
|
$spreadsheet->addNamedRange(new \PhpOffice\PhpSpreadsheet\NamedRange('namedCell', $workSheet, 'A4')); |
25
|
|
|
$workSheet->setCellValue('B1', 'uPPER'); |
26
|
|
|
$workSheet->setCellValue('B2', '=TRUE()'); |
27
|
|
|
$workSheet->setCellValue('B3', '=FALSE()'); |
28
|
|
|
|
29
|
|
|
$ws2 = $spreadsheet->createSheet(); |
30
|
|
|
$ws2->setCellValue('A1', 100); |
31
|
|
|
$ws2->setCellValue('A2', 200); |
32
|
|
|
$ws2->setTitle('Sheet2'); |
33
|
|
|
$spreadsheet->addNamedRange(new \PhpOffice\PhpSpreadsheet\NamedRange('A2B', $ws2, 'A2')); |
34
|
|
|
|
35
|
|
|
$spreadsheet->setActiveSheetIndex(0); |
36
|
|
|
$cell2 = $workSheet->getCell('D1'); |
37
|
|
|
$cell2->setValue($formula); |
38
|
|
|
$result = $cell2->getCalculatedValue(); |
39
|
|
|
self::assertEquals($expectedResult, $result); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function providerFunctionsAsString() |
43
|
|
|
{ |
44
|
|
|
return require 'data/Calculation/FunctionsAsString.php'; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|