Merge afc047221d3cfdad8c2c824ab08ee3f1efb81352 into 84596668410bea89d21aa9867b91e1550e359329

This commit is contained in:
PiotrNH 2022-05-26 15:55:27 +02:00 committed by GitHub
commit c0185a0c6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 5 deletions

View File

@ -12,7 +12,7 @@
}
],
"require": {
"php": ">=7.3.0",
"php": ">=8.0",
"ext-zip": "*",
"ext-xmlreader": "*",
"ext-dom": "*"

View File

@ -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,17 @@ class WriterEntityFactory
*/
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);
}

View File

@ -141,7 +141,9 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry
$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