Skip to content

Commit

Permalink
fix: 移除空行(通过delete删除的行会被读到)
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Jul 2, 2018
1 parent 657ee43 commit 6f06d59
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Service/Excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function parseToArray($file, $cols, $startRow = 2, $maxRow = 1000)

$data = $sheet->toArray();
$data = array_slice($data, $startRow - 1);
$data = $this->removeNullRow($data);

if (!$data) {
return $this->err('表格数据为空,请根据范例填写后再提交', -3);
Expand All @@ -51,4 +52,17 @@ public function parseToArray($file, $cols, $startRow = 2, $maxRow = 1000)
'data' => $data,
]);
}

protected function removeNullRow($data)
{
for ($i = count($data) - 1; $i > 0; $i--) {
$row = array_unique($data[$i]);
if ($row == [null]) {
unset($data[$i]);
} else {
return $data;
}
}
return $data;
}
}

0 comments on commit 6f06d59

Please sign in to comment.