30 lines
848 B
PHP
30 lines
848 B
PHP
<?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');
|
|
}
|
|
}
|