spout icon indicating copy to clipboard operation
spout copied to clipboard

Incorrect type reported when adding an unsupported type to a cell

Open cmanley opened this issue 3 years ago • 0 comments

I'm using version 3.3.0. I experienced this exception and I've seen it reported in another ticket #713 where someone tried to pass an array as value to a cell entity: "Trying to add a value with an unsupported type: NULL"

The wrong type is reported because

Box\Spout\Common\Entity->getValue() has this line: return !$this->isError() ? $this->value : null;

and Box\Spout\Writer\XLSX\Manager->getCellXML() throws the exception doing this: throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . \gettype($cell->getValue()));

so of course it'll always report NULL as type.

So perhaps the cell's getValue() should return the actual value even if it is an unsupported type, but everything reading the cell should check isError() first. That's one way. Another way would be to to create another version of getValue() by another name (e.g. getActualValue()) and use that in the exception message.

That'll save users a lot of confusion.

cmanley avatar Mar 15 '22 18:03 cmanley