This commit is contained in:
philipp lang 2024-06-30 23:35:37 +02:00
parent 496330aec8
commit c1d0221dcd
1 changed files with 12 additions and 3 deletions

View File

@ -21,7 +21,7 @@ class TableDocumentData extends Data
) { ) {
} }
public function compile(string $path): void public function compile(string $path): string
{ {
$this->spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$this->spreadsheet->getProperties() $this->spreadsheet->getProperties()
@ -32,7 +32,7 @@ class TableDocumentData extends Data
$this->spreadsheet->getActiveSheet()->setTitle('unfilled'); $this->spreadsheet->getActiveSheet()->setTitle('unfilled');
foreach ($this->sheets as $sheet) { foreach ($this->sheets as $sheet) {
$this->addSheet($sheet); $this->compileSheet($sheet);
} }
$this->spreadsheet->setActiveSheetIndex(0); $this->spreadsheet->setActiveSheetIndex(0);
@ -40,9 +40,18 @@ class TableDocumentData extends Data
$writer = new Xlsx($this->spreadsheet); $writer = new Xlsx($this->spreadsheet);
$writer->save($path); $writer->save($path);
$this->spreadsheet->disconnectWorksheets(); $this->spreadsheet->disconnectWorksheets();
return $path;
} }
public function addSheet(SheetData $sheet): void public function addSheet(SheetData $sheet): self
{
$this->sheets[] = $sheet;
return $this;
}
private function compileSheet(SheetData $sheet): void
{ {
if ('unfilled' !== $this->spreadsheet->getActiveSheet()->getTitle()) { if ('unfilled' !== $this->spreadsheet->getActiveSheet()->getTitle()) {
$this->spreadsheet->addSheet(new Worksheet($this->spreadsheet, $sheet->name)); $this->spreadsheet->addSheet(new Worksheet($this->spreadsheet, $sheet->name));