Skip to content

Cell object formulaAttributes property stores SimpleXMLElement preventing serialization #1757

Closed
@tristanleboss

Description

@tristanleboss

This is:

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

What is the expected behavior?

For example, if you want to cache a PhpSpreadsheet object using redis or apcu to avoid re-reading an excel file again and again, you need to be able to serialize a PhpSpreadsheet object. Unfortunately, PHP can't serialize a SimpleXMLElement and you will receive an exception Serialization of 'SimpleXMLElement' is not allowed.

The culprit is the formulaAttributes private property of class PhpOffice\PhpSpreadsheet\Cell\Cell.
This property is used by a getter and a setter in this class but doesn't really seems to be used (yet!) anywhere else in the project.

There is just one use of the setter in the Xslx reader and some commented code in the Worksheet class in writeCellFormula method.

What is the current behavior?

I think it would be a good idea to transform this SimpleXMLElement object containing the attributes of the c (cell) XML tag into a real basic PHP array. So, the formulaAttributes property would be a basic array instead of a SimpleXMLElement.

What are the steps to reproduce?

Create an excel file with value 1 in A1 and =A1+1 formula in A2, then extend the formula to 10 rows.
This will create a shared formula. This way some c XML tag will have both t="shared" and s="(int)" attributes.

Then, read the Excel file and try to serialize the resulting PhpOffice\PhpSpreadsheet\Spreadsheet object with:

serialize($spreadsheet)

Which versions of PhpSpreadsheet and PHP are affected?

1.15.0

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