From 8e87c392a5cbf76a73b3fc4d065b8ab02069fe58 Mon Sep 17 00:00:00 2001 From: Piotr Nguyen Ha Date: Mon, 16 May 2022 11:07:17 +0200 Subject: [PATCH] allows to pass format as array for each column --- composer.json | 2 +- .../Writer/Common/Creator/WriterEntityFactory.php | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 8bdd265..b3781a2 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 f07e5f0..e6333f9 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\Row; 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,12 @@ class WriterEntityFactory */ public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null) { - $cells = \array_map(function ($cellValue) { - return new Cell($cellValue); - }, $cellValues); + $format = $rowStyle?->getFormat(); + + $cells = \array_map(function ($k, $cellValue) { + $cellStyle = (new StyleBuilder())->setFormat($format[$k] ?? '@')->build(); + return new Cell($cellValue, $cellStyle); + }, array_keys($cellValues), $cellValues); return new Row($cells, $rowStyle); }