diff --git a/src/Spout/Writer/XLSX/Internal/Worksheet.php b/src/Spout/Writer/XLSX/Internal/Worksheet.php index be67e19..b78748c 100644 --- a/src/Spout/Writer/XLSX/Internal/Worksheet.php +++ b/src/Spout/Writer/XLSX/Internal/Worksheet.php @@ -131,36 +131,38 @@ EOD; $rowIndex = $this->lastWrittenRowIndex + 1; $numCells = count($dataRow); - $data = ''; + $rowXML = ''; foreach($dataRow as $cellValue) { $columnIndex = CellHelper::getCellIndexFromColumnIndex($cellNumber); - $data .= 'getId() . '"'; + $cellXML = 'getId() . '"'; if (CellHelper::isNonEmptyString($cellValue)) { if ($this->shouldUseInlineStrings) { - $data .= ' t="inlineStr">' . $this->stringsEscaper->escape($cellValue) . ''; + $cellXML .= ' t="inlineStr">' . $this->stringsEscaper->escape($cellValue) . ''; } else { $sharedStringId = $this->sharedStringsHelper->writeString($cellValue); - $data .= ' t="s">' . $sharedStringId . ''; + $cellXML .= ' t="s">' . $sharedStringId . ''; } } else if (CellHelper::isBoolean($cellValue)) { - $data .= ' t="b">' . $cellValue . ''; + $cellXML .= ' t="b">' . $cellValue . ''; } else if (CellHelper::isNumeric($cellValue)) { - $data .= '>' . $cellValue . ''; + $cellXML .= '>' . $cellValue . ''; } else if (empty($cellValue)) { - $data .= '/>'; + // 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; $cellNumber++; } - $data .= ''; + $rowXML .= ''; - $wasWriteSuccessful = fwrite($this->sheetFilePointer, $data); + $wasWriteSuccessful = fwrite($this->sheetFilePointer, $rowXML); if ($wasWriteSuccessful === false) { throw new IOException("Unable to write data in {$this->worksheetFilePath}"); }