allows to pass format as array for each column
This commit is contained in:
parent
0739e044da
commit
8e87c392a5
@ -12,7 +12,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.3.0",
|
"php": ">=8.0",
|
||||||
"ext-zip": "*",
|
"ext-zip": "*",
|
||||||
"ext-xmlreader": "*",
|
"ext-xmlreader": "*",
|
||||||
"ext-dom": "*"
|
"ext-dom": "*"
|
||||||
|
@ -7,6 +7,7 @@ use Box\Spout\Common\Entity\Row;
|
|||||||
use Box\Spout\Common\Entity\Style\Style;
|
use Box\Spout\Common\Entity\Style\Style;
|
||||||
use Box\Spout\Common\Exception\UnsupportedTypeException;
|
use Box\Spout\Common\Exception\UnsupportedTypeException;
|
||||||
use Box\Spout\Common\Type;
|
use Box\Spout\Common\Type;
|
||||||
|
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
|
||||||
use Box\Spout\Writer\WriterInterface;
|
use Box\Spout\Writer\WriterInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,9 +102,12 @@ class WriterEntityFactory
|
|||||||
*/
|
*/
|
||||||
public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null)
|
public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null)
|
||||||
{
|
{
|
||||||
$cells = \array_map(function ($cellValue) {
|
$format = $rowStyle?->getFormat();
|
||||||
return new Cell($cellValue);
|
|
||||||
}, $cellValues);
|
$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);
|
return new Row($cells, $rowStyle);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user