diff --git a/www/go/core/data/convert/AbstractConverter.php b/www/go/core/data/convert/AbstractConverter.php index 0eeeb69e29..eeb55350ae 100644 --- a/www/go/core/data/convert/AbstractConverter.php +++ b/www/go/core/data/convert/AbstractConverter.php @@ -290,7 +290,7 @@ protected function finishImport(): void * @param array $params * @return Blob */ - public final function exportToBlob(Query $entities, array $params = []): Blob + public function exportToBlob(Query $entities, array $params = []): Blob { $this->clientParams = $params; $this->entitiesQuery = $entities; @@ -310,7 +310,7 @@ public final function exportToBlob(Query $entities, array $params = []): Blob /** * @var Query */ - private $entitiesQuery; + protected $entitiesQuery; /** * The query used for exporting entities diff --git a/www/go/core/data/convert/Spreadsheet.php b/www/go/core/data/convert/Spreadsheet.php index 491b876b7b..e87733b828 100644 --- a/www/go/core/data/convert/Spreadsheet.php +++ b/www/go/core/data/convert/Spreadsheet.php @@ -228,18 +228,39 @@ protected function exportEntity(Entity $entity): void $this->writeRecord($record); } + /** + * @param \go\core\orm\Query $entities + * @param array $params + * @return \go\core\fs\Blob + * @throws \go\core\orm\exception\SaveException + */ + public function exportToBlob(Query $entities, array $params = []): Blob + { + $this->clientParams = $params; + $this->entitiesQuery = $entities; + $this->initExport(); - protected function finishExport(): Blob + $this->index = 0; + foreach($entities as $entity) { + $this->exportEntity($entity); + $this->index++; + } + + $this->colorizeHeaders(); + + return $this->finishExport(); + } + + /** + * @return void + */ + protected function colorizeHeaders(): void { - switch($this->extension) { + switch ($this->extension) { case 'html': - fputs($this->fp, ""); - break; case 'csv': - break; default: - $headerStyle = [ 'font' => [ 'bold' => true, @@ -258,7 +279,25 @@ protected function finishExport(): Blob $colDim = $this->spreadsheet->getActiveSheet()->getColumnDimension($col->getColumnIndex()); $colDim->setAutoSize(true); } + break; + } + } + /** + * @return \go\core\fs\Blob + * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws \go\core\orm\exception\SaveException + */ + protected function finishExport(): Blob + { + switch($this->extension) { + case 'html': + fputs($this->fp, ""); + break; + case 'csv': + + break; + default: $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($this->spreadsheet); $writer->setPreCalculateFormulas(false); $writer->save($this->tempFile->getPath());