Avoid NULL in String Function Call (#3617)

The overall problem is described in issue #3613. This PR represents only a partial solution. Very complicated formulas are resulting in calls to string functions using null arguments, which is deprecated in recent Php releases. In fact, there are many such deprecations for the spreadsheet in question. Eliminating the deprecations is easy. However, the result of the calculation is, for many cells, 0 rather than what Excel determines it should be. This can be overlooked to a certain extent, because Excel will recalculate when the spreadsheet is opened, so loading and saving the spreadsheet in question will result in a spreadsheet which looks okay when it is opened in Excel. Resolving the incorrect calculation in PhpSpreadsheet would be nice, so I'm leaving the issue open, but that looks too complicated for me to get a toehold.
This commit is contained in:
oleibman
2023-06-22 12:41:53 -07:00
committed by GitHub
parent f1d90aa46c
commit 263a4a4934
3 changed files with 26 additions and 1 deletions
+1 -1
View File
@@ -153,7 +153,7 @@ class Functions
{
$condition = self::flattenSingleValue($condition);
if ($condition === '') {
if ($condition === '' || $condition === null) {
return '=""';
}
if (!is_string($condition) || !in_array($condition[0], ['>', '<', '='], true)) {
@@ -0,0 +1,25 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class Issue3613Test extends AbstractFunctional
{
private static string $testbook = 'tests/data/Reader/XLSX/issue.3613.xlsx';
// Partial fix only. We will no longer throw exception on save.
// But calculation for cell value is 0, which is incorrect.
public function testIssue3613(): void
{
$reader = new Xlsx();
$spreadsheet = $reader->load(self::$testbook);
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
$spreadsheet->disconnectWorksheets();
$sheet = $reloadedSpreadsheet->getActiveSheet();
self::assertSame('=ROUND(MAX((O4-P4)*{0.03;0.1;0.2;0.25;0.3;0.35;0.45}-{0;2520;16920;31920;52920;85920;181920},0)-Q4,2)', $sheet->getCell('N4')->getValue());
$reloadedSpreadsheet->disconnectWorksheets();
}
}
Binary file not shown.