diff --git a/src/ExecutionEngine/Util/StepConfig.php b/src/ExecutionEngine/Util/StepConfig.php index 2b8216167..26a23bf6b 100644 --- a/src/ExecutionEngine/Util/StepConfig.php +++ b/src/ExecutionEngine/Util/StepConfig.php @@ -33,6 +33,7 @@ enum StepConfig: string case CONFIG_FILTERS = 'filters'; case SETTINGS_DELIMITER = 'delimiter'; case SETTINGS_HEADER = 'header'; + case SETTINGS_SHEET_NAME = 'sheetName'; case SETTINGS_HEADER_NO_HEADER = 'no_header'; case SETTINGS_HEADER_TITLE = 'title'; case SETTINGS_HEADER_NAME = 'name'; diff --git a/src/Export/Attribute/Request/ExportDataRequestBody.php b/src/Export/Attribute/Request/ExportDataRequestBody.php index 4391474bd..62f54bf39 100644 --- a/src/Export/Attribute/Request/ExportDataRequestBody.php +++ b/src/Export/Attribute/Request/ExportDataRequestBody.php @@ -44,6 +44,12 @@ enum: StepConfig::values(), type: 'string', example: ';' ); + } else { + $configProperties[] = new Property( + property: StepConfig::SETTINGS_SHEET_NAME->value, + type: 'string', + example: 'Sheet1' + ); } parent::__construct( content: new JsonContent( diff --git a/src/Export/Attribute/Request/ExportFolderDataRequestBody.php b/src/Export/Attribute/Request/ExportFolderDataRequestBody.php index aeefa6d34..0b1d5c592 100644 --- a/src/Export/Attribute/Request/ExportFolderDataRequestBody.php +++ b/src/Export/Attribute/Request/ExportFolderDataRequestBody.php @@ -45,6 +45,12 @@ enum: StepConfig::values(), type: 'string', example: ';' ); + } else { + $configProperties[] = new Property( + property: StepConfig::SETTINGS_SHEET_NAME->value, + type: 'string', + example: 'Sheet1' + ); } parent::__construct( diff --git a/src/Export/ExecutionEngine/AutomationAction/Messenger/Handler/XlsxCreationHandler.php b/src/Export/ExecutionEngine/AutomationAction/Messenger/Handler/XlsxCreationHandler.php index 528723e10..d98b8187d 100644 --- a/src/Export/ExecutionEngine/AutomationAction/Messenger/Handler/XlsxCreationHandler.php +++ b/src/Export/ExecutionEngine/AutomationAction/Messenger/Handler/XlsxCreationHandler.php @@ -65,6 +65,7 @@ public function __invoke(XlsxCreationMessage $message): void $columns = $this->extractConfigFieldFromJobStepConfig($message, StepConfig::CONFIG_COLUMNS->value); $settings = $this->extractConfigFieldFromJobStepConfig($message, StepConfig::CONFIG_CONFIGURATION->value); $headers = $settings[StepConfig::SETTINGS_HEADER->value] ?? StepConfig::SETTINGS_HEADER_NO_HEADER->value; + $sheetName = $settings[StepConfig::SETTINGS_SHEET_NAME->value] ?? null; if (!isset($jobRun->getContext()[StepConfig::GRID_EXPORT_DATA->value])) { $this->abort($this->getAbortData( @@ -86,7 +87,9 @@ public function __invoke(XlsxCreationMessage $message): void $headers !== StepConfig::SETTINGS_HEADER_NO_HEADER->value, $headers === StepConfig::SETTINGS_HEADER_NAME ), - $user + $user, + null, + $sheetName ); } catch (Exception $e) { $this->abort($this->getAbortData( diff --git a/src/Export/Service/AbstractExportService.php b/src/Export/Service/AbstractExportService.php index 945cac93f..7a294dda5 100644 --- a/src/Export/Service/AbstractExportService.php +++ b/src/Export/Service/AbstractExportService.php @@ -47,6 +47,7 @@ public function createExportFile( GridExportData $gridExportData, UserInterface $user, ?string $delimiter = null, + ?string $sheetName = null, ): void { $storage = $this->storageService->getTempStorage(); @@ -64,7 +65,7 @@ public function createExportFile( ); } - $this->generateExportFile($id, $storage, $headers, $gridExportData->getExportData(), $delimiter); + $this->generateExportFile($id, $storage, $headers, $gridExportData->getExportData(), $delimiter, $sheetName); } /** @@ -89,7 +90,8 @@ abstract protected function generateExportFile( FilesystemOperator $storage, array $headers, array $exportData, - string $delimiter + string $delimiter, + ?string $sheetName = null, ): void; /** diff --git a/src/Export/Service/CsvExportService.php b/src/Export/Service/CsvExportService.php index 954d9e6bb..41d174fd6 100644 --- a/src/Export/Service/CsvExportService.php +++ b/src/Export/Service/CsvExportService.php @@ -36,7 +36,8 @@ protected function generateExportFile( FilesystemOperator $storage, array $headers, array $exportData, - string $delimiter + string $delimiter, + ?string $sheetName = null, ): void { $data = []; diff --git a/src/Export/Service/ExportServiceInterface.php b/src/Export/Service/ExportServiceInterface.php index 2766ad11a..4bd57537d 100644 --- a/src/Export/Service/ExportServiceInterface.php +++ b/src/Export/Service/ExportServiceInterface.php @@ -27,6 +27,7 @@ public function createExportFile( GridExportData $gridExportData, UserInterface $user, ?string $delimiter = null, + ?string $sheetName = null, ): void; /** diff --git a/src/Export/Service/XlsxExportService.php b/src/Export/Service/XlsxExportService.php index 1e54c6f8f..54a0eb9e5 100644 --- a/src/Export/Service/XlsxExportService.php +++ b/src/Export/Service/XlsxExportService.php @@ -35,13 +35,19 @@ protected function generateExportFile( FilesystemOperator $storage, array $headers, array $exportData, - string $delimiter + string $delimiter, + ?string $sheetName = null, ): void { $csvReader = new Csv(); $csvReader->setDelimiter($delimiter); $csvReader->setSheetIndex(0); $spreadsheet = $csvReader->loadSpreadsheetFromString($this->processData($delimiter, $headers, $exportData)); + + if ($sheetName !== null && $sheetName !== '') { + $spreadsheet->getActiveSheet()->setTitle($sheetName); + } + $writer = new Xlsx($spreadsheet); $stream = fopen('php://temp', 'rb+'); $writer->save($stream);