From ce7248c015a80fd63f213155d689bf58936c59c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benny=20G=C3=A5rdbo-Pedersen?= Date: Thu, 19 Sep 2019 14:02:08 +0200 Subject: [PATCH] Fixed bug with cell indexes in Row not being respected when rendering a Row --- src/Spout/Writer/XLSX/Manager/WorksheetManager.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php index b0e458f..1c45c5a 100644 --- a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php +++ b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php @@ -153,16 +153,17 @@ EOD; */ private function addNonEmptyRow(Worksheet $worksheet, Row $row) { - $cellIndex = 0; $rowStyle = $row->getStyle(); $rowIndex = $worksheet->getLastWrittenRowIndex() + 1; - $numCells = $row->getNumCells(); + $numCells = max(array_keys($row->getCells()))+1; $rowXML = ''; - foreach ($row->getCells() as $cell) { - $rowXML .= $this->applyStyleAndGetCellXML($cell, $rowStyle, $rowIndex, $cellIndex); - $cellIndex++; + $cells = $row->getCells(); + for($cell_index=0;$cell_index<$numCells;$cell_index++) { + if(isset($cells[$cell_index])) { + $rowXML .= $this->applyStyleAndGetCellXML($cells[$cell_index], $rowStyle, $rowIndex, $cell_index); + } } $rowXML .= '';