forked from PHPOffice/PhpSpreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Xlsx Reader Shared Formula with Boolean Results
A solution, at least in part, for issue PHPOffice#4280. Xlsx Reader is not handling shared formulae correctly. As a result, some cells are treated as if they contain boolean values rather than formulae.
- Loading branch information
Showing
3 changed files
with
45 additions
and
6 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
37 changes: 37 additions & 0 deletions
37
tests/PhpSpreadsheetTests/Reader/Xlsx/SharedFormulaeTest.php
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; | ||
|
||
use PhpOffice\PhpSpreadsheet\IOFactory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class SharedFormulaeTest extends TestCase | ||
{ | ||
public function testSharedFormulae(): void | ||
{ | ||
// Boolean functions were not handled correctly. | ||
$filename = 'tests/data/Reader/XLSX/sharedformulae.xlsx'; | ||
$reader = IOFactory::createReader('Xlsx'); | ||
$spreadsheet = $reader->load($filename); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
$expected = [ | ||
[1, '=A1+1', '=A1>3', '="x"&A1'], | ||
[2, '=A2+1', '=A2>3', '="x"&A2'], | ||
[3, '=A3+1', '=A3>3', '="x"&A3'], | ||
[4, '=A4+1', '=A4>3', '="x"&A4'], | ||
[5, '=A5+1', '=A5>3', '="x"&A5'], | ||
]; | ||
self::assertSame($expected, $sheet->toArray(null, false, false)); | ||
$expected = [ | ||
[1, 2, false, 'x1'], | ||
[2, 3, false, 'x2'], | ||
[3, 4, false, 'x3'], | ||
[4, 5, true, 'x4'], | ||
[5, 6, true, 'x5'], | ||
]; | ||
self::assertSame($expected, $sheet->toArray(null, true, false)); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
} |
Binary file not shown.