FIX: columns

This commit is contained in:
Juan Pablo Vial
2022-03-07 22:31:07 -03:00
parent 26bac169de
commit e8aa00e121

View File

@ -12,9 +12,24 @@ class Informe
$this->spreadsheet = new Spreadsheet();
return $this;
}
protected function formatArray(array $data)
{
$maxCols = 0;
foreach ($data as $row) {
if (count($row) > $maxCols) {
$maxCols = count($row);
}
}
foreach ($data as &$row) {
if (count($row) < $maxCols) {
$row = array_merge($row, array_fill(0, $maxCols - count($row), ''));
}
}
return $data;
}
public function addArray(array $data, string $start = 'A1')
{
$this->spreadsheet->getActiveSheet()->fromArray($data, null, $start);
$this->spreadsheet->getActiveSheet()->fromArray($this->formatArray($data), null, $start);
return $this;
}
public function send(string $filename)