Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cell.php: Passing null to parameter #1 ($string) of type string is deprecated #3613

Closed
FFCZ opened this issue Jun 13, 2023 · 7 comments
Closed

Comments

@FFCZ
Copy link

FFCZ commented Jun 13, 2023

This is:

- [x] a bug report

php 8.2.6 + PhpSpreadsheet 1.28.0
my project , recently upgraded php 7.4 to 8.4, frequent errors occur when reading excel, but not found in old php 7.4

warning tips:
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php
line: 393
msg: aa!N4 -> bb!O4 -> strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated

It may be an adaptation issue to the new environment. hope can be compatible it. thank you!

What is the expected behavior?

What is the current behavior?

What are the steps to reproduce?

What features do you think are causing the issue

- [x] Reader

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

Which versions of PhpSpreadsheet and PHP are affected?

@oleibman
Copy link
Collaborator

It would be helpful if you could upload the failing spreadsheet so that we can verify the problem and confirm that any fix that we make solves it.

@FFCZ
Copy link
Author

FFCZ commented Jun 14, 2023

tax.xlsx

@FFCZ
Copy link
Author

FFCZ commented Jun 14, 2023

The Excel file I used will generate the same error during the PHP 8.2.6 test.
Checking the official document, in PHP 8.1, 'Passing null to non nullable internal function parameters is deprecated.'.
https://www.php.net/releases/8.1/en.php
May be necessary to improve the relevant code, such as $aa? '' Or (string) $aa

$Reader = $path_info['extension'] === 'xls' ? new Xls() : new Xlsx();
$Spreadsheet = $Reader->load($op_file);
$sheet_num = $Spreadsheet->getSheetCount();
for ($i = 0; $i < $sheet_num; $i++) {
$Spreadsheet->setActiveSheetIndex($i);
$Spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
$Spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(PageSetup::PAPERSIZE_A4);
$Spreadsheet->getActiveSheet()->getPageSetup()->setFitToWidth(1);
$Spreadsheet->getActiveSheet()->getPageSetup()->setFitToHeight(0);
$Spreadsheet->getActiveSheet()->getPageMargins()->setTop(0.39);
$Spreadsheet->getActiveSheet()->getPageMargins()->setRight(0.39);
$Spreadsheet->getActiveSheet()->getPageMargins()->setLeft(0.39);
$Spreadsheet->getActiveSheet()->getPageMargins()->setBottom(0.39);
}
$Writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($Spreadsheet);
$Writer->save($op_file2);
unset($Reader, $Writer);

@oleibman
Copy link
Collaborator

Thank you for the sample file. I am not sure what makes your spreadsheet so "special", but I definitely duplicate your problem.

@oleibman
Copy link
Collaborator

As a workaround, you should be able to avoid the error with:

$Writer->setPreCalculateFormulas(false);

In the meantime, there seem to be at least 2 different problems associated with your spreadsheet. The first, dealing with the null value, is easy to deal with, and I will probably have something ready in the next few days.

The other problem is that you have extremely complicated formulas, and the Calculation Engine, although it does not throw an exception, is unable to handle some of them correctly. I think it is likely that this inability is what is causing the unexpected null value to appear in the first place. Fixing that part of this problem is probably very difficult.

@FFCZ
Copy link
Author

FFCZ commented Jun 15, 2023

Thanks for your reply. The null issue was caused by a change in the new version of PHP.
And the formula is really a bit complicated. It is used by financial colleagues to calculate personal income tax.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Jun 16, 2023
The overall problem is described in issue PHPOffice#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.
@oleibman
Copy link
Collaborator

PR 3617 should eliminate the exceptions. It does not fix the incorrect internal calculations, which may or may not be adequate for your use case. I have used the debugging features available in PhpSpreadsheet, and cannot even see where it's going wrong, let alone how. Disabling branch pruning is a suggestion that has sometimes worked for Calculation problems, but it not only does not succeed here, it causes a new exception.

oleibman added a commit that referenced this issue Jun 22, 2023
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.
@FFCZ FFCZ closed this as completed Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants