Skip to content
This repository was archived by the owner on May 26, 2022. It is now read-only.

Commit e276b43

Browse files
authored
Fix crash when using associative array with empty row (#354)
1 parent 9ce7740 commit e276b43

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Spout/Writer/XLSX/Internal/Worksheet.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ public function addRow($dataRow, $style)
149149
private function isEmptyRow($dataRow)
150150
{
151151
$numCells = count($dataRow);
152-
return ($numCells === 1 && CellHelper::isEmpty($dataRow[0]));
152+
// using "reset()" instead of "$dataRow[0]" because $dataRow can be an associative array
153+
return ($numCells === 1 && CellHelper::isEmpty(reset($dataRow)));
153154
}
154155

155156
/**

tests/Spout/Writer/XLSX/WriterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public function testAddRowShouldNotWriteEmptyRows()
294294
$dataRows = [
295295
[''],
296296
['xlsx--21', 'xlsx--22'],
297-
[''],
297+
['key' => ''],
298298
[''],
299299
['xlsx--51', 'xlsx--52'],
300300
];

0 commit comments

Comments
 (0)