Change to xlsx file
This commit is contained in:
29
app/Service/Informe/Informe.php
Normal file
29
app/Service/Informe/Informe.php
Normal 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');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user