Skip to content

Commit

Permalink
also add empty cols if assoc is false
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Jan 24, 2025
1 parent 48e99ad commit 47957d2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Xlsx/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public function readFile(
continue;
}
$rowData = array_combine($headers, $rowData);
} else {
// Assume the first row indicates how many cells we want
if ($totalColumns === null) {
$totalColumns = count($rowData);
}
}
yield $rowData;
}
Expand Down
43 changes: 43 additions & 0 deletions tests/SpreadCompatXlsxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,48 @@ public function testNativeDontSkipEmptyCols()
'col7' => null,
]
], $arr);

$Native = new Native();
$data = $Native->readFile(__DIR__ . '/data/empty-col-2.xlsx');

$arr = iterator_to_array($data);
$this->assertEquals([
[
'col1',
'col2',
'col3',
'col4',
'col5',
'col6',
'col7',
],
[
"v1",
"v2",
null,
"v4",
null,
null,
null,
],
[
"v1",
null,
null,
"v4",
null,
null,
null,
],
[
null,
"v2",
"v3",
null,
null,
null,
null,
]
], $arr);
}
}

0 comments on commit 47957d2

Please sign in to comment.