Skip to content

Commit e2f83c8

Browse files
authored
Update Excel.php
1 parent 1d036af commit e2f83c8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Utils/Excel.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,15 @@ public static function handleCalculateSheet(Event $event)
8484
public static function toArray(array $row, $replaceFlag = ['*'], $targetFlag = ''): array
8585
{
8686
$data = [];
87+
88+
// num: 兼容表头出现空的情况
89+
$num = 0;
8790
foreach ($row as $key => $value) {
8891
$rowKey = str_replace($replaceFlag, $targetFlag, $key);
92+
if (!empty($rowKey)) {
93+
$rowKey = trim($rowKey);
94+
$rowKey = $rowKey ?: $num;
95+
}
8996

9097
// can be call after handleCalculateSheet, will auto calcute cell value
9198
// this line is fallback if not call Excel::handleCalculateSheet($event)
@@ -95,6 +102,8 @@ public static function toArray(array $row, $replaceFlag = ['*'], $targetFlag = '
95102
}
96103

97104
$data[$rowKey] = $newValue ?: null;
105+
106+
$num++;
98107
}
99108

100109
return $data;

0 commit comments

Comments
 (0)