Change to xlsx file

This commit is contained in:
Juan Pablo Vial
2022-03-07 22:21:42 -03:00
parent 726794923d
commit 3b473bcefa
2 changed files with 38 additions and 2 deletions

View File

@ -0,0 +1,29 @@
<?php
namespace App\Service\Informe;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
class Informe
{
protected $spreadsheet;
public function createSpreadsheet()
{
$this->spreadsheet = new Spreadsheet();
return $this;
}
public function addArray(array $data, string $start = 'A1')
{
$this->spreadsheet->getActiveSheet()->fromArray($data, null, $start);
return $this;
}
public function send(string $filename)
{
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment;filename='{$filename}'");
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($this->spreadsheet, 'Xlsx');
$writer->save('php://output');
}
}