diff --git a/src/Spout/Writer/Common/Creator/EntityFactory.php b/src/Spout/Writer/Common/Creator/EntityFactory.php index b9ebef4..91d7576 100644 --- a/src/Spout/Writer/Common/Creator/EntityFactory.php +++ b/src/Spout/Writer/Common/Creator/EntityFactory.php @@ -49,11 +49,12 @@ class EntityFactory /** * @param mixed $cellValue + * @param Style|null $cellStyle * @return Cell */ - public static function createCell($cellValue) + public static function createCell($cellValue, Style $cellStyle = null) { - return new Cell($cellValue); + return new Cell($cellValue, $cellStyle); } /** @@ -66,14 +67,14 @@ class EntityFactory /** * @param array $cells - * @param Style|null $style + * @param Style|null $rowStyle * @return Row */ - public static function createRow(array $cells, Style $style = null) + public static function createRow(array $cells = [], Style $rowStyle = null) { $styleMerger = new StyleMerger(); $rowManager = new RowManager($styleMerger); - return new Row($cells, $style, $rowManager); + return new Row($cells, $rowStyle, $rowManager); } } diff --git a/src/Spout/Writer/ODS/Manager/WorksheetManager.php b/src/Spout/Writer/ODS/Manager/WorksheetManager.php index 7b44e35..4eb559e 100644 --- a/src/Spout/Writer/ODS/Manager/WorksheetManager.php +++ b/src/Spout/Writer/ODS/Manager/WorksheetManager.php @@ -153,8 +153,8 @@ class WorksheetManager implements WorksheetManagerInterface { // Apply styles - the row style is merged at this point $cell->applyStyle($rowStyle); - $this->styleManager->applyExtraStylesIfNeeded($cell); - $registeredStyle = $this->styleManager->registerStyle($cell->getStyle()); + $newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell); + $registeredStyle = $this->styleManager->registerStyle($newCellStyle); $styleIndex = $registeredStyle->getId() + 1; // 1-based $numTimesValueRepeated = ($nextCellIndex - $currentCellIndex); diff --git a/src/Spout/Writer/WriterAbstract.php b/src/Spout/Writer/WriterAbstract.php index 062d71c..5409961 100644 --- a/src/Spout/Writer/WriterAbstract.php +++ b/src/Spout/Writer/WriterAbstract.php @@ -227,17 +227,15 @@ abstract class WriterAbstract implements WriterInterface * @TODO: Move this into styleMerger * * @param Row $row - * @return $this */ private function applyDefaultRowStyle(Row $row) { $defaultRowStyle = $this->optionsManager->getOption(Options::DEFAULT_ROW_STYLE); - if ($defaultRowStyle === null) { - return $this; - } - $mergedStyle = $this->styleMerger->merge($row->getStyle(), $defaultRowStyle); - $row->setStyle($mergedStyle); + if ($defaultRowStyle !== null) { + $mergedStyle = $this->styleMerger->merge($row->getStyle(), $defaultRowStyle); + $row->setStyle($mergedStyle); + } } /** diff --git a/src/Spout/Writer/XLSX/Manager/Style/StyleManager.php b/src/Spout/Writer/XLSX/Manager/Style/StyleManager.php index a87e9d8..f5af61f 100644 --- a/src/Spout/Writer/XLSX/Manager/Style/StyleManager.php +++ b/src/Spout/Writer/XLSX/Manager/Style/StyleManager.php @@ -204,8 +204,8 @@ EOD; foreach ($registeredStyles as $style) { $styleId = $style->getId(); - $fillId = $this->styleRegistry->getFillIdForStyleId($styleId); - $borderId = $this->styleRegistry->getBorderIdForStyleId($styleId); + $fillId = $this->getFillIdForStyleId($styleId); + $borderId = $this->getBorderIdForStyleId($styleId); $content .= 'styleRegistry->getFillIdForStyleId($styleId) ?: 0); + } + + /** + * Returns the fill ID associated to the given style ID. + * For the default style, we don't a border. + * + * @param int $styleId + * @return int + */ + private function getBorderIdForStyleId($styleId) + { + // For the default style (ID = 0), we don't want to override the border. + // Otherwise all cells of the spreadsheet will have a border. + $isDefaultStyle = ($styleId === 0); + + return $isDefaultStyle ? 0 : ($this->styleRegistry->getBorderIdForStyleId($styleId) ?: 0); + } + /** * Returns the content of the "" section. * diff --git a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php index 0363f7c..3701b93 100644 --- a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php +++ b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php @@ -174,8 +174,8 @@ EOD; { // Apply styles - the row style is merged at this point $cell->applyStyle($rowStyle); - $this->styleManager->applyExtraStylesIfNeeded($cell); - $registeredStyle = $this->styleManager->registerStyle($cell->getStyle()); + $newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell); + $registeredStyle = $this->styleManager->registerStyle($newCellStyle); return $this->getCellXML($rowIndex, $cellIndex, $cell, $registeredStyle->getId()); }