diff --git a/src/Spout/Writer/XLSX/Internal/Worksheet.php b/src/Spout/Writer/XLSX/Internal/Worksheet.php index 354554a..0d365a8 100644 --- a/src/Spout/Writer/XLSX/Internal/Worksheet.php +++ b/src/Spout/Writer/XLSX/Internal/Worksheet.php @@ -134,29 +134,7 @@ EOD; $rowXML = ''; foreach($dataRow as $cellValue) { - $columnIndex = CellHelper::getCellIndexFromColumnIndex($cellNumber); - $cellXML = 'getId() . '"'; - - if (CellHelper::isNonEmptyString($cellValue)) { - if ($this->shouldUseInlineStrings) { - $cellXML .= ' t="inlineStr">' . $this->stringsEscaper->escape($cellValue) . ''; - } else { - $sharedStringId = $this->sharedStringsHelper->writeString($cellValue); - $cellXML .= ' t="s">' . $sharedStringId . ''; - } - } else if (CellHelper::isBoolean($cellValue)) { - $cellXML .= ' t="b">' . intval($cellValue) . ''; - } else if (CellHelper::isNumeric($cellValue)) { - $cellXML .= '>' . $cellValue . ''; - } else if (empty($cellValue)) { - // don't write empty cells (not appending to $cellXML is the right behavior!) - $cellXML = ''; - } else { - throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . gettype($cellValue)); - } - - $rowXML .= $cellXML; + $rowXML .= $this->getCellXml($rowIndex, $cellNumber, $cellValue, $style->getId()); $cellNumber++; } @@ -171,6 +149,43 @@ EOD; $this->lastWrittenRowIndex++; } + /** + * Build and return xml for a single cell. + * + * @param int $rowIndex + * @param int $cellNumber + * @param mixed $cellValue + * @param int $styleId + * @return string + * @throws InvalidArgumentException + */ + private function getCellXml($rowIndex, $cellNumber, $cellValue, $styleId) + { + $columnIndex = CellHelper::getCellIndexFromColumnIndex($cellNumber); + $cellXML = 'shouldUseInlineStrings) { + $cellXML .= ' t="inlineStr">' . $this->stringsEscaper->escape($cellValue) . ''; + } else { + $sharedStringId = $this->sharedStringsHelper->writeString($cellValue); + $cellXML .= ' t="s">' . $sharedStringId . ''; + } + } else if (CellHelper::isBoolean($cellValue)) { + $cellXML .= ' t="b">' . intval($cellValue) . ''; + } else if (CellHelper::isNumeric($cellValue)) { + $cellXML .= '>' . $cellValue . ''; + } else if (empty($cellValue)) { + // don't write empty cells (not appending to $cellXML is the right behavior!) + $cellXML = ''; + } else { + throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . gettype($cellValue)); + } + + return $cellXML; + } + /** * Closes the worksheet *