Default row style should only apply to existing cells

This commit is contained in:
Adrien Loison committed 2017-11-05 12:17:45 +01:00
1 parent 727a90fd06
commit ca5962271e
5 files changed
+48 -17

No files matched your search

@@ -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 .= '<xf numFmtId="0" fontId="' . $styleId . '" fillId="' . $fillId . '" borderId="' . $borderId . '" xfId="0"';
@@ -229,6 +229,38 @@ EOD;
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.
*