diff --git a/src/Spout/Writer/Exception/InvalidDataException.php b/src/Spout/Writer/Exception/InvalidDataException.php new file mode 100644 index 0000000..adaae1f --- /dev/null +++ b/src/Spout/Writer/Exception/InvalidDataException.php @@ -0,0 +1,12 @@ +' . PHP_EOL; - } else { - if (is_numeric($cellValue)) { + switch(true) { + case empty($cellValue): + $data .= '/>' . PHP_EOL; + break; + case gettype($cellValue) === 'integer': + case gettype($cellValue) === 'boolean': + case gettype($cellValue) === 'float': $data .= '>' . $cellValue . '' . PHP_EOL; - } else { + break; + case gettype($cellValue) === 'object' && method_exists($cellValue, '__toString'): + $cellValue = (string)$cellValue; + case gettype($cellValue) === 'string': if ($this->shouldUseInlineStrings) { $data .= ' t="inlineStr">' . $this->stringsEscaper->escape($cellValue) . '' . PHP_EOL; } else { $sharedStringId = $this->sharedStringsHelper->writeString($cellValue); $data .= ' t="s">' . $sharedStringId . '' . PHP_EOL; } - } + break; + default: + throw new InvalidDataException("Invalid data type " . gettype($cellValue)); } $cellNumber++;