Skip to content

Commit

Permalink
add as many missing column as necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Jan 24, 2025
1 parent f994881 commit 48e99ad
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Xlsx/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function readFile(
}

// expand missing columns at the end
if ($totalColumns && $col < $totalColumns) {
while ($totalColumns && $col < $totalColumns) {
$rowData[] = null;
$col++;
}
Expand Down
35 changes: 35 additions & 0 deletions tests/SpreadCompatXlsxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,40 @@ public function testNativeDontSkipEmptyCols()
'col4' => null,
]
], $arr);

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

$arr = iterator_to_array($data);
$this->assertEquals([
[
'col1' => "v1",
'col2' => "v2",
'col3' => null,
'col4' => "v4",
'col5' => null,
'col6' => null,
'col7' => null,
],
[
'col1' => "v1",
'col2' => null,
'col3' => null,
'col4' => "v4",
'col5' => null,
'col6' => null,
'col7' => null,
],
[
'col1' => null,
'col2' => "v2",
'col3' => "v3",
'col4' => null,
'col5' => null,
'col6' => null,
'col7' => null,
]
], $arr);
}
}
Binary file added tests/data/empty-col-2.xlsx
Binary file not shown.

0 comments on commit 48e99ad

Please sign in to comment.