-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Calculations containing #REF!
no longer throw exceptions from 1.26.0
#3453
Comments
Throwing an Exception certainly doesn't seem like the right action. Propagating The case where PhpSpreadsheet and Excel are not the same is your case, when you provide a literal |
Thanks for the response @oleibman, I had not realised that this was connected to #2870/#2902. It also, looks like #2902 was released in 1.24.0 but this issue is not present until 1.26.0, so maybe it's not connected? I agree that propagating I had also not realised that providing
However, having just tested both of the above cases using the script I posted above, I can confirm that PHPSpreadsheet returns I still believe this is incorrect since Excel will return PS. I can confirm that the literal string xl/worksheets/sheet1.xmlIn cell
|
I'll concur with propagating the Excel '#REF!' error. |
@ndench I am not duplicating one of your results in Excel at all. If I take a blank sheet in Excel, and enter I do mostly agree with your 'sheet delete' example. Excel shows the formula as you describe it; however, when you save the workbook, it is saved as |
PhpSpreadsheet doesn't handle ranges unless they're top-left/bottom-right.
I did a PR related to setting '#REF!' on deleting rows/columns; but I can't find which PR it was... need to search when I'm more awake |
My apologies, it seems my previous comment was riddled with typos. I was working through multiple cases in Excel and seem to have messed up my explanation. I certainly did not mean to use ranges that cross rows/columns. Here are my examples again, explained correctly with my Excel files attached 😅
Excel file showing steps 1-3: ref-error-step1-3.xlsx For reference, I'm using Office Professional Plus 2016 on Windows 10. Regardless, I think we're largely agreed that PHPSpreadsheet should return
I've tested with Excel a few different things.
|
=SUM(B1:INDIRECT("XYZ")) If you store a cellRef (e.g. Then delete row 2; this gives a nested '#REF!' for the INDIRECT() call that should trickle up: |
Fix PHPOffice#3453. User sets a valid formula (e.g. `=SUM(Sheet2!B1:Sheet2!B3)`), and then does something to invalidate the formula (e.g. delete Sheet2). Excel changes the formula to `SUM(#REF!:#REF!)` when the spreadsheet is saved; apparently someone thought this was a good idea. But PhpSpreadsheet (a) used to throw an Exception when it evaluated the formula, and (b) now gives a result of `0` when evaluating the formula. Neither is ideal. It would be better to propagate the `#REF!` error. It is likely that more tests are needed, which is why I will keep this in draft status for a bit.
@ndench @MarkBaker Please test and suggest additional tests for PR #3467. I think it handles everything discussed above, but there are probably other situations that need to be addressed. |
Fix #3453. User sets a valid formula (e.g. `=SUM(Sheet2!B1:Sheet2!B3)`), and then does something to invalidate the formula (e.g. delete Sheet2). Excel changes the formula to `SUM(#REF!:#REF!)` when the spreadsheet is saved; apparently someone thought this was a good idea. But PhpSpreadsheet (a) used to throw an Exception when it evaluated the formula, and (b) now gives a result of `0` when evaluating the formula. Neither is ideal. It would be better to propagate the `#REF!` error. It is likely that more tests are needed, which is why I will keep this in draft status for a bit.
This is:
What is the expected behavior?
Prior to version
1.26.0
calculating the value of a formula that contains a reference error (eg.=SUM(B1:#REF!)
) would result in aWhat is the current behavior?
From
1.26.0
until now (1.28.0
) the result is0
instead of an exception.What are the steps to reproduce?
What features do you think are causing the issue
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
I have tested with
.xlsx
, don't see why it wouldn't affect all other formats.Which versions of PhpSpreadsheet and PHP are affected?
PHP 8.1.16
PHPSpreadsheet 1.26.0+ (until at least 1.28.0)
The text was updated successfully, but these errors were encountered: