-
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.
Merge pull request #4271 from oleibman/issue4269
Add forceFullCalc Option to Xlsx Writer
- Loading branch information
Showing
5 changed files
with
100 additions
and
5 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,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx; | ||
|
||
use PhpOffice\PhpSpreadsheet\Shared\File; | ||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class Issue4269Test extends TestCase | ||
{ | ||
private string $outputFile = ''; | ||
|
||
protected function tearDown(): void | ||
{ | ||
if ($this->outputFile !== '') { | ||
unlink($this->outputFile); | ||
$this->outputFile = ''; | ||
} | ||
} | ||
|
||
#[DataProvider('validationProvider')] | ||
public function testWriteArrayFormulaTextJoin( | ||
bool $preCalculateFormulas, | ||
?bool $forceFullCalc, | ||
string $expected | ||
): void { | ||
$spreadsheet = new Spreadsheet(); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
$sheet->setCellValue('A1', '=A2*2'); | ||
$sheet->setCellValue('A2', 0); | ||
|
||
$writer = new XlsxWriter($spreadsheet); | ||
$writer->setPreCalculateFormulas($preCalculateFormulas); | ||
if ($forceFullCalc !== null) { | ||
$writer->setForceFullCalc($forceFullCalc); | ||
} | ||
$this->outputFile = File::temporaryFilename(); | ||
$writer->save($this->outputFile); | ||
$spreadsheet->disconnectWorksheets(); | ||
|
||
$file = 'zip://'; | ||
$file .= $this->outputFile; | ||
$file .= '#xl/workbook.xml'; | ||
$data = file_get_contents($file); | ||
if ($data === false) { | ||
self::fail('Unable to read file'); | ||
} else { | ||
self::assertStringContainsString($expected, $data); | ||
} | ||
} | ||
|
||
public static function validationProvider(): array | ||
{ | ||
return [ | ||
'normal case' => [true, null, 'calcMode="auto" calcCompleted="1" fullCalcOnLoad="0" forceFullCalc="0"'], | ||
'issue 456' => [false, null, 'calcMode="auto" calcCompleted="0" fullCalcOnLoad="1" forceFullCalc="1"'], | ||
'better choice for no precalc' => [false, false, 'calcMode="auto" calcCompleted="0" fullCalcOnLoad="1" forceFullCalc="0"'], | ||
'unlikely use case' => [true, true, 'calcMode="auto" calcCompleted="1" fullCalcOnLoad="0" forceFullCalc="1"'], | ||
]; | ||
} | ||
} |