Skip to content

Attempt to read property "f" on null #2677

Closed
@technghiath

Description

@technghiath

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?

  • Not appear ErrorException

What is the current behavior?

  • I received an ErrorException, but I don't know which cell it is from from the excel template file
    image

What are the steps to reproduce?

I would like to create PR fix as below:

....
$node->addAttribute('sqref', $item->children('xm', true)->sqref ?? null);
$node->addChild('formula1', $item->formula1->children('xm', true)->f ?? null);
....

I'm worried, will this affect performance?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

...src\PhpSpreadsheet\Reader\Xlsx.php
....
    /**
     * Loads Spreadsheet from file.
     */
    public function load(string $filename, int $flags = 0): Spreadsheet
    {
       ...
        $node->addAttribute('sqref', $item->children('xm', true)->sqref);
        $node->addChild('formula1', $item->formula1->children('xm', true)->f);
      ...
    }

https://github.com/PHPOffice/PhpSpreadsheet/blob/master/src/PhpSpreadsheet/Reader/Xlsx.php#L901-L902

Which versions of PhpSpreadsheet and PHP are affected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    data validationsreader/xlsxReader for MS OfficeOpenXML-format (xlsx) spreadsheet files

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions