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.
19_NamedRange.php was not changed to use absolute addressing when that was introduced to Named Ranges. Consequently, the output from this sample has been wrong ever since, for both Xls and Xlsx. There was an additional problem with Xls. It appears that the Xls Writer Parser does not parse multiple concatenations using the ampersand operator correctly. So, `=B1+" "+B2` was parsed as `=B1+" "`. I believe that this is due to ampersand being treated as a condition rather than an operator; `A1>A2>A3` isn't valid, but `A1&A2&A3` is. My original PR (PHPOffice#1992, which I will now close) only partially resolved this, but I think moving ampersand handling from `condition` to `expression` is fully successful. There are already more than ample tests for Named Ranges, so I did not add a new one for that purpose. However, I did add a new test for the Xls parser problem.
- Loading branch information
Showing
3 changed files
with
35 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
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,28 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xls; | ||
|
||
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; | ||
|
||
class Sample19Test extends AbstractFunctional | ||
{ | ||
public function testSample19Xls(): void | ||
{ | ||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); | ||
$spreadsheet->setActiveSheetIndex(0); | ||
$spreadsheet->getActiveSheet()->setCellValue('A1', 'Firstname:') | ||
->setCellValue('A2', 'Lastname:') | ||
->setCellValue('A3', 'Fullname:') | ||
->setCellValue('B1', 'Maarten') | ||
->setCellValue('B2', 'Balliauw') | ||
->setCellValue('B3', '=B1 & " " & B2') | ||
->setCellValue('C1', '=A2&A3&A3&A2&B1'); | ||
|
||
$robj = $this->writeAndReload($spreadsheet, 'Xls'); | ||
$sheet0 = $robj->setActiveSheetIndex(0); | ||
// Xls parser eliminates unneeded whitespace | ||
self::assertEquals('=B1&" "&B2', $sheet0->getCell('B3')->getValue()); | ||
self::assertEquals('Maarten Balliauw', $sheet0->getCell('B3')->getCalculatedValue()); | ||
self::assertEquals('Lastname:Fullname:Fullname:Lastname:Maarten', $sheet0->getCell('C1')->getCalculatedValue()); | ||
} | ||
} |