0

Hi all,

I'm using PHP with PHPExcel to create an excel sheet that I can then send as an email using mail().

Everything is working but the conditional formatting.

My code is as follows for the conditional formatting part:

// Conditions for data
$objConditional1 = new PHPExcel_Style_Conditional();
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
                ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_GREATERTHAN)
                ->addCondition('15');
$objConditional1->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_GREEN);

$objConditional2 = new PHPExcel_Style_Conditional();
$objConditional2->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
                ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_LESSTHAN)
                ->addCondition('10');
$objConditional2->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED);

$conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('B'.$row_condition_start)->getConditionalStyles();
array_push($conditionalStyles, $objConditional1);
array_push($conditionalStyles, $objConditional2);
$objPHPExcel->getActiveSheet()->getStyle('B'.$row_condition_start)->setConditionalStyles($conditionalStyles);

//  duplicate the conditional styles across a range of cells
$row_condition_start++;
$row_number--;

echo date('H:i:s') , " Duplicate the conditional formatting across a range of cells" , EOL;
$objPHPExcel->getActiveSheet()->duplicateConditionalStyle(
                $objPHPExcel->getActiveSheet()->getStyle('B'.$row_condition_start)->getConditionalStyles(),
                'B'.$row_condition_start.':B'.$row_number
              );

Where $row_condition_start == 4 before this code snippet and $row_number == 9.
I am trying to use the conditional formatting on cells B4:B8.
If the cell value > 15 => Green, and < 10 => Red.

I can't see where I'm going wrong.

Thanks for any help offered.

1
Contributor
1
Reply
4
Views
4 Years
Discussion Span
Last Post by Tinnin
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.