Phpspreadsheet: Conditional Formatting with Fill solid does not change background

Created on 10 Feb 2017  路  2Comments  路  Source: PHPOffice/PhpSpreadsheet

$conditional = new Conditional();
$conditional ->setConditionType(Conditional::CONDITION_CELLIS);
$conditional ->setOperatorType(Conditional::OPERATOR_GREATERTHANOREQUAL);
$conditional ->addCondition(0);
$conditional ->getStyle()->applyFromArray([
  "fill" => [
    "type" => Fill::FILL_SOLID,
    "color" => ["rgb" => "000000"]
  ]
]);

The above code will not change the background color.

startcolor will not work either but endcolor will

Most helpful comment

For the case that somebody comes here with the same problem but has set the fill color this way:

$conditional->getStyle()->getFill()->setFillType(Fill::FILL_SOLID);
$conditional->getStyle()->getFill()->getStartColor()->setARGB(Color::COLOR_GREEN);

Just add the following line:

$conditional->getStyle()->getFill()->getEndColor()->setARGB(Color::COLOR_GREEN);

Then it should work ;-)

All 2 comments

For the case that somebody comes here with the same problem but has set the fill color this way:

$conditional->getStyle()->getFill()->setFillType(Fill::FILL_SOLID);
$conditional->getStyle()->getFill()->getStartColor()->setARGB(Color::COLOR_GREEN);

Just add the following line:

$conditional->getStyle()->getFill()->getEndColor()->setARGB(Color::COLOR_GREEN);

Then it should work ;-)

Thank you @naitsirch for your comment. Has same problem. Works with from applyFromArray() too.

    protected function setFill($color)
    {
        return [
            'fill' => [
                'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
                'startColor' => [
                    'argb' => $color,
                ],
                'endColor' => [
                    'argb' => $color,
                ],
            ],
        ];
    }

Was this page helpful?
0 / 5 - 0 ratings