diff --git a/composer.json b/composer.json index 8bdd2659..b3781a26 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "php": ">=7.3.0", + "php": ">=8.0", "ext-zip": "*", "ext-xmlreader": "*", "ext-dom": "*" diff --git a/src/Spout/Writer/Common/Creator/WriterEntityFactory.php b/src/Spout/Writer/Common/Creator/WriterEntityFactory.php index f07e5f01..d54b9324 100644 --- a/src/Spout/Writer/Common/Creator/WriterEntityFactory.php +++ b/src/Spout/Writer/Common/Creator/WriterEntityFactory.php @@ -7,6 +7,7 @@ use Box\Spout\Common\Entity\Style\Style; use Box\Spout\Common\Exception\UnsupportedTypeException; use Box\Spout\Common\Type; +use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; use Box\Spout\Writer\WriterInterface; /** @@ -101,9 +102,17 @@ public static function createRow(array $cells = [], Style $rowStyle = null) */ public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null) { - $cells = \array_map(function ($cellValue) { - return new Cell($cellValue); - }, $cellValues); + $format = $rowStyle?->getFormat(); + $cellStyles = []; + + if (is_array($format)) { + foreach ($format as $k => $f) + $cellStyles[$k] = (new StyleBuilder())->setFormat($f ?? '@')->build(); + } + + $cells = \array_map(function ($k, $cellValue) use ($cellStyles) { + return new Cell($cellValue, $cellStyles[$k] ?? null); + }, array_keys(array_values($cellValues)), $cellValues); return new Row($cells, $rowStyle); } diff --git a/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php b/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php index 14eb9862..3452e47e 100644 --- a/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php +++ b/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php @@ -141,7 +141,9 @@ protected function registerFormat(Style $style) $styleId = $style->getId(); $format = $style->getFormat(); - if ($format) { + + // If format is passed as array then skip it from add it to rowstyles + if (!is_array($format)) { $isFormatRegistered = isset($this->registeredFormats[$format]); // We need to track the already registered format definitions