Skip to content

setValueExplicit sets the Value wrongly? to "0" instead of "null" #2488

@Wolfy7

Description

@Wolfy7

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

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:

                $this->value = 0 + $pValue;

to

                if(is_null($pValue)){
                    $this->value = null;
                }else{
                    $this->value = 0 + $pValue;
                }

If you want you can assigne this to me and i will provide a PR with this fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions