Informe tesoreria en excel
This commit is contained in:
63
app/src/Service/Informe/Excel.php
Normal file
63
app/src/Service/Informe/Excel.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Informe;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet;
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
class Excel implements Define\Informe
|
||||
{
|
||||
protected string $title;
|
||||
protected string $filename;
|
||||
protected array $data;
|
||||
|
||||
public function setTitle(string $title): Excel
|
||||
{
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
public function setFilename(string $filename): Excel
|
||||
{
|
||||
$this->filename = $filename;
|
||||
return $this;
|
||||
}
|
||||
public function addData(array $rows): Excel
|
||||
{
|
||||
foreach ($rows as $row) {
|
||||
$this->addRow($row);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function addRow(array $row): Excel
|
||||
{
|
||||
foreach ($row as $cell) {
|
||||
$this->addCell($cell);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function addCell(PhpSpreadsheet\Cell\Cell $cell): Excel
|
||||
{
|
||||
$this->data []= $cell;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function build(): void
|
||||
{
|
||||
$spreadsheet = new PhpSpreadsheet\Spreadsheet();
|
||||
$spreadsheet->getProperties()
|
||||
->setCreator('admin@incoviba.cl')
|
||||
->setSubject($this->title)
|
||||
->setCompany('Incoviba')
|
||||
->setTitle($this->title);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->setTitle($this->title);
|
||||
|
||||
foreach ($this->data as $rowIndex => $row) {
|
||||
foreach ($row as $columnIndex => $cell) {
|
||||
$sheet->getCell([$columnIndex + 1, $rowIndex + 1])->setValue($cell);
|
||||
}
|
||||
}
|
||||
|
||||
$writer = PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||||
$writer->save($this->filename);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user