-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ods defined names unit tests (#2054)
* Defined names/formulae in ODS are prefixed by $$ when used in a formula; so we need to strip this out to fully convert them to an Excel formula * Test for ODS Writer for DefinedNames
- Loading branch information
Mark Baker
authored
May 3, 2021
1 parent
83e55cf
commit fd14da1
Showing
7 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods; | ||
|
||
use PhpOffice\PhpSpreadsheet\Reader\Ods; | ||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DefinedNamesTest extends TestCase | ||
{ | ||
/** | ||
* @var Spreadsheet | ||
*/ | ||
private $spreadsheet; | ||
|
||
protected function setUp(): void | ||
{ | ||
$filename = 'tests/data/Reader/Ods/DefinedNames.ods'; | ||
$reader = new Ods(); | ||
$this->spreadsheet = $reader->load($filename); | ||
} | ||
|
||
public function testDefinedNames(): void | ||
{ | ||
$worksheet = $this->spreadsheet->getActiveSheet(); | ||
|
||
$firstDefinedNameValue = $worksheet->getCell('First')->getValue(); | ||
$secondDefinedNameValue = $worksheet->getCell('Second')->getValue(); | ||
$calculatedFormulaValue = $worksheet->getCell('B2')->getCalculatedValue(); | ||
|
||
self::assertSame(3, $firstDefinedNameValue); | ||
self::assertSame(4, $secondDefinedNameValue); | ||
self::assertSame(12, $calculatedFormulaValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Writer\Ods; | ||
|
||
use PhpOffice\PhpSpreadsheet\NamedFormula; | ||
use PhpOffice\PhpSpreadsheet\NamedRange; | ||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; | ||
|
||
class DefinedNamesTest extends AbstractFunctional | ||
{ | ||
public function testDefinedNamesWriter(): void | ||
{ | ||
$spreadsheet = new Spreadsheet(); | ||
$worksheet = $spreadsheet->getActiveSheet(); | ||
|
||
$dataSet = [ | ||
[7, 'x', 5], | ||
['=', '=FORMULA'], | ||
]; | ||
$worksheet->fromArray($dataSet, null, 'A1'); | ||
|
||
$spreadsheet->addDefinedName(new NamedRange('FIRST', $worksheet, '$A$1')); | ||
$spreadsheet->addDefinedName(new NamedRange('SECOND', $worksheet, '$C$1')); | ||
$spreadsheet->addDefinedName(new NamedFormula('FORMULA', $worksheet, '=FIRST*SECOND')); | ||
|
||
$reloaded = $this->writeAndReload($spreadsheet, 'Ods'); | ||
|
||
self::assertSame(7, $reloaded->getActiveSheet()->getCell('FIRST')->getValue()); | ||
self::assertSame(5, $reloaded->getActiveSheet()->getCell('SECOND')->getValue()); | ||
self::assertSame(35, $reloaded->getActiveSheet()->getCell('B2')->getCalculatedValue()); | ||
} | ||
} |
Binary file not shown.