allows to pass format as array for each column

This commit is contained in:
Piotr Nguyen Ha committed 2022-05-16 11:07:17 +02:00
1 parent 0739e044da
commit 8e87c392a5
2 files changed
+8 -4

No files matched your search

@@ -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);
}