Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

allow to pass format as array for each column #890

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"php": ">=7.3.0",
"php": ">=8.0",
"ext-zip": "*",
"ext-xmlreader": "*",
"ext-dom": "*"
Expand Down
15 changes: 12 additions & 3 deletions src/Spout/Writer/Common/Creator/WriterEntityFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down