diff --git a/src/Spout/Writer/Common/Entity/Row.php b/src/Spout/Writer/Common/Entity/Row.php index 56e7ab2..bc6f94f 100644 --- a/src/Spout/Writer/Common/Entity/Row.php +++ b/src/Spout/Writer/Common/Entity/Row.php @@ -26,7 +26,7 @@ class Row /** * Row constructor. - * @param array $cells + * @param Cell[] $cells * @param Style|null $style */ public function __construct(array $cells = [], Style $style = null) @@ -39,7 +39,7 @@ class Row } /** - * @return array + * @return Cell[] $cells */ public function getCells() { @@ -48,9 +48,9 @@ class Row /** * @param array $cells - * @return Row + * @return $this */ - public function setCells($cells) + public function setCells(array $cells) { $this->cells = []; foreach ($cells as $cell) { @@ -82,7 +82,7 @@ class Row /** * @param Style $style|null - * @return $this + * @return Row */ public function applyStyle(Style $style = null) { diff --git a/src/Spout/Writer/Common/Manager/CellManager.php b/src/Spout/Writer/Common/Manager/CellManager.php new file mode 100644 index 0000000..be79b59 --- /dev/null +++ b/src/Spout/Writer/Common/Manager/CellManager.php @@ -0,0 +1,37 @@ +styleMerger = $styleMerger; + } + + /** + * Merges a Style into a cells Style. + * + * @param Cell $cell + * @param Style $style + * @return $this + */ + public function applyStyle(Cell $cell, Style $style) + { + $mergedStyle = $this->styleMerger->merge($cell->getStyle(), $style); + $cell->setStyle($mergedStyle); + } +} \ No newline at end of file diff --git a/src/Spout/Writer/Common/Manager/RowManager.php b/src/Spout/Writer/Common/Manager/RowManager.php new file mode 100644 index 0000000..49c6e9d --- /dev/null +++ b/src/Spout/Writer/Common/Manager/RowManager.php @@ -0,0 +1,34 @@ +styleMerger = $styleMerger; + } + + /** + * @param Style $style + * @return $this + */ + public function applyStyle(Row $row, Style $style) + { + $mergedStyle = $this->styleMerger->merge($row->getStyle(), $style); + $row->setStyle($mergedStyle); + } +} \ No newline at end of file diff --git a/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php b/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php index 4732d04..66c186c 100644 --- a/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php +++ b/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php @@ -6,6 +6,7 @@ use Box\Spout\Common\Exception\IOException; use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface; use Box\Spout\Writer\Common\Entity\Options; use Box\Spout\Writer\Common\Manager\Style\StyleManagerInterface; +use Box\Spout\Writer\Common\Entity\Row; use Box\Spout\Writer\Common\Entity\Sheet; use Box\Spout\Writer\Common\Entity\Workbook; use Box\Spout\Writer\Common\Entity\Worksheet; diff --git a/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php b/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php index 0c23f7f..ebfe922 100644 --- a/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php +++ b/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php @@ -7,7 +7,6 @@ use Box\Spout\Writer\Common\Entity\Sheet; use Box\Spout\Writer\Common\Entity\Row; use Box\Spout\Writer\Common\Entity\Workbook; use Box\Spout\Writer\Common\Entity\Worksheet; -use Box\Spout\Writer\Common\Sheet; use Box\Spout\Writer\Exception\SheetNotFoundException; use Box\Spout\Writer\Exception\WriterException; diff --git a/src/Spout/Writer/ODS/Manager/WorksheetManager.php b/src/Spout/Writer/ODS/Manager/WorksheetManager.php index 5a46254..7b2a242 100644 --- a/src/Spout/Writer/ODS/Manager/WorksheetManager.php +++ b/src/Spout/Writer/ODS/Manager/WorksheetManager.php @@ -30,7 +30,7 @@ class WorksheetManager implements WorksheetManagerInterface /** * WorksheetManager constructor. - * + * @param StyleManager $styleManager * @param \Box\Spout\Common\Escaper\ODS $stringsEscaper * @param StringHelper $stringHelper */ @@ -91,7 +91,6 @@ class WorksheetManager implements WorksheetManagerInterface return $tableElement; } - /** /** * Adds a row to the worksheet. * @@ -116,7 +115,7 @@ class WorksheetManager implements WorksheetManagerInterface for ($i = 0; $i < $cellsCount; $i++) { /** @var Cell $cell */ - $cell = $row->getCells()[$currentCellIndex]; + $cell = $cells[$currentCellIndex]; /** @var Cell|null $nextCell */ $nextCell = isset($cells[$nextCellIndex]) ? $cells[$nextCellIndex] : null; diff --git a/src/Spout/Writer/WriterAbstract.php b/src/Spout/Writer/WriterAbstract.php index ecba0db..3a08838 100644 --- a/src/Spout/Writer/WriterAbstract.php +++ b/src/Spout/Writer/WriterAbstract.php @@ -344,20 +344,25 @@ abstract class WriterAbstract implements WriterInterface throw new InvalidArgumentException('The "$style" argument must be a Style instance and cannot be NULL.'); } - $this->addRows(array_map(function ($row) use ($style) { + foreach($dataRows as $row) { + if (is_array($row)) { - return $this->createRowFromArray($row, $style); + $row = $this->createRowFromArray($row, $style); } elseif ($row instanceof Row) { - return $row; + $row->setStyle($style); } else { throw new InvalidArgumentException(); } - }, $dataRows)); + + $this->addRow($row); + } return $this; } /** + * @TODO: Move this into styleMerger + * * @param Row $row * @return $this */ @@ -367,9 +372,8 @@ abstract class WriterAbstract implements WriterInterface if (null === $defaultRowStyle) { return $this; } - $merged = $this->styleMerger->merge($row->getStyle(), $defaultRowStyle); - $row->setStyle($merged); - return $this; + $mergedStyle = $this->styleMerger->merge($row->getStyle(), $defaultRowStyle); + $row->setStyle($mergedStyle); } /**