PHPExcel Conditional Formatting Empty Cell

I’ve spent about an hour trying to get this working, so i’ll post it here.

To get a spreadsheet automatically marking any empty cell in a column in dark red, use the following incantation:

$conditional = new PHPExcel_Style_Conditional();
$conditional->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
    ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_EQUAL)
        ->addCondition(0);
$conditional->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(PHPExcel_Style_Color::COLOR_DARKRED);

One thought on “PHPExcel Conditional Formatting Empty Cell

  1. I would suggest to use
    $conditional->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
    ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_EQUAL)
    ->addCondition(‘””‘);
    Instead of … addCondition(0)
    because 0 is not empty 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *