Informe tesoreria en excel

This commit is contained in:
Juan Pablo Vial
2024-02-23 22:37:09 -03:00
parent 5156858205
commit cfe18c1909
14 changed files with 809 additions and 131 deletions

View 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);
}
}