Default row style should only apply to existing cells
This commit is contained in:
parent
727a90fd06
commit
ca5962271e
@ -49,11 +49,12 @@ class EntityFactory
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $cellValue
|
* @param mixed $cellValue
|
||||||
|
* @param Style|null $cellStyle
|
||||||
* @return Cell
|
* @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 array $cells
|
||||||
* @param Style|null $style
|
* @param Style|null $rowStyle
|
||||||
* @return Row
|
* @return Row
|
||||||
*/
|
*/
|
||||||
public static function createRow(array $cells, Style $style = null)
|
public static function createRow(array $cells = [], Style $rowStyle = null)
|
||||||
{
|
{
|
||||||
$styleMerger = new StyleMerger();
|
$styleMerger = new StyleMerger();
|
||||||
$rowManager = new RowManager($styleMerger);
|
$rowManager = new RowManager($styleMerger);
|
||||||
|
|
||||||
return new Row($cells, $style, $rowManager);
|
return new Row($cells, $rowStyle, $rowManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,8 +153,8 @@ class WorksheetManager implements WorksheetManagerInterface
|
|||||||
{
|
{
|
||||||
// Apply styles - the row style is merged at this point
|
// Apply styles - the row style is merged at this point
|
||||||
$cell->applyStyle($rowStyle);
|
$cell->applyStyle($rowStyle);
|
||||||
$this->styleManager->applyExtraStylesIfNeeded($cell);
|
$newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||||
$registeredStyle = $this->styleManager->registerStyle($cell->getStyle());
|
$registeredStyle = $this->styleManager->registerStyle($newCellStyle);
|
||||||
$styleIndex = $registeredStyle->getId() + 1; // 1-based
|
$styleIndex = $registeredStyle->getId() + 1; // 1-based
|
||||||
|
|
||||||
$numTimesValueRepeated = ($nextCellIndex - $currentCellIndex);
|
$numTimesValueRepeated = ($nextCellIndex - $currentCellIndex);
|
||||||
|
@ -227,18 +227,16 @@ abstract class WriterAbstract implements WriterInterface
|
|||||||
* @TODO: Move this into styleMerger
|
* @TODO: Move this into styleMerger
|
||||||
*
|
*
|
||||||
* @param Row $row
|
* @param Row $row
|
||||||
* @return $this
|
|
||||||
*/
|
*/
|
||||||
private function applyDefaultRowStyle(Row $row)
|
private function applyDefaultRowStyle(Row $row)
|
||||||
{
|
{
|
||||||
$defaultRowStyle = $this->optionsManager->getOption(Options::DEFAULT_ROW_STYLE);
|
$defaultRowStyle = $this->optionsManager->getOption(Options::DEFAULT_ROW_STYLE);
|
||||||
if ($defaultRowStyle === null) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ($defaultRowStyle !== null) {
|
||||||
$mergedStyle = $this->styleMerger->merge($row->getStyle(), $defaultRowStyle);
|
$mergedStyle = $this->styleMerger->merge($row->getStyle(), $defaultRowStyle);
|
||||||
$row->setStyle($mergedStyle);
|
$row->setStyle($mergedStyle);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@ -204,8 +204,8 @@ EOD;
|
|||||||
|
|
||||||
foreach ($registeredStyles as $style) {
|
foreach ($registeredStyles as $style) {
|
||||||
$styleId = $style->getId();
|
$styleId = $style->getId();
|
||||||
$fillId = $this->styleRegistry->getFillIdForStyleId($styleId);
|
$fillId = $this->getFillIdForStyleId($styleId);
|
||||||
$borderId = $this->styleRegistry->getBorderIdForStyleId($styleId);
|
$borderId = $this->getBorderIdForStyleId($styleId);
|
||||||
|
|
||||||
$content .= '<xf numFmtId="0" fontId="' . $styleId . '" fillId="' . $fillId . '" borderId="' . $borderId . '" xfId="0"';
|
$content .= '<xf numFmtId="0" fontId="' . $styleId . '" fillId="' . $fillId . '" borderId="' . $borderId . '" xfId="0"';
|
||||||
|
|
||||||
@ -229,6 +229,38 @@ EOD;
|
|||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the fill ID associated to the given style ID.
|
||||||
|
* For the default style, we don't a fill.
|
||||||
|
*
|
||||||
|
* @param int $styleId
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private function getFillIdForStyleId($styleId)
|
||||||
|
{
|
||||||
|
// For the default style (ID = 0), we don't want to override the fill.
|
||||||
|
// Otherwise all cells of the spreadsheet will have a background color.
|
||||||
|
$isDefaultStyle = ($styleId === 0);
|
||||||
|
|
||||||
|
return $isDefaultStyle ? 0 : ($this->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 "<cellStyles>" section.
|
* Returns the content of the "<cellStyles>" section.
|
||||||
*
|
*
|
||||||
|
@ -174,8 +174,8 @@ EOD;
|
|||||||
{
|
{
|
||||||
// Apply styles - the row style is merged at this point
|
// Apply styles - the row style is merged at this point
|
||||||
$cell->applyStyle($rowStyle);
|
$cell->applyStyle($rowStyle);
|
||||||
$this->styleManager->applyExtraStylesIfNeeded($cell);
|
$newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||||
$registeredStyle = $this->styleManager->registerStyle($cell->getStyle());
|
$registeredStyle = $this->styleManager->registerStyle($newCellStyle);
|
||||||
|
|
||||||
return $this->getCellXML($rowIndex, $cellIndex, $cell, $registeredStyle->getId());
|
return $this->getCellXML($rowIndex, $cellIndex, $cell, $registeredStyle->getId());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user