-
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
setValueExplicit sets the Value wrongly? to "0" instead of "null" #2488
Comments
It does raise the question of why you want to specify type |
@MarkBaker justified question.
So if I read this file in PHPspreadsheet converts this empty cell to "0" cause if the t="n". Maybe the XLSX (XML) file is not "correct" but that's what I don't know. And also just for my understanding I think if a cell is empty it should stay empty independent of the type. So probably the function should always return empty if the value is null or? Thanks for your reply. |
Fix PHPOffice#2488. When Excel sees this situation, it leaves the value of the cell as null rather than casting to the specified DataType. It doesn't really make sense to change setValueExplicit to adopt this convention; it should be sufficient to recognize the situation in the Reader and act there. The same sort of situation might apply to strings, but I don't see any practical difference between null string and null even if so.
Fix #2488. When Excel sees this situation, it leaves the value of the cell as null rather than casting to the specified DataType. It doesn't really make sense to change setValueExplicit to adopt this convention; it should be sufficient to recognize the situation in the Reader and act there. The same sort of situation might apply to strings, but I don't see any practical difference between null string and null even if so.
This is:
What is the expected behavior?
If you want to set the Value explicit to TYPE_Numeric but the value ($pValue) ist "null" the value should be also set to "null".
What is the current behavior?
If a Cell looks like that in the xml-file:
<c r="A1" s="109" t="n" />
the Value for this cell will be set to "0" instead of "null".
What are the steps to reproduce?
If you call setValueExplicit with $pValue = null and $pDataType = DataType::TYPE_NUMERIC the value will be set to "0".
Which versions of PhpSpreadsheet and PHP are affected?
PhpSpeadsheet = 1.18.0 - 2021-05-31
PHP = 7.2.4
Possible solution
Change the line 217 in \src\PhpSpreadsheet\Cell\Cell.php from:
to
If you want you can assigne this to me and i will provide a PR with this fix.
The text was updated successfully, but these errors were encountered: