Jimmyt1988
Jimmyt1988

Reputation: 21176

PHPExcel conditional formatting not quite right

I'm trying to add a border to the bottom of all cells in every row after row 2 that satisfies this condition:

$objConditional1 = new PHPExcel_Style_Conditional();
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION)
                ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_EQUAL)
                ->addCondition('AND((B2<>B3),B2<>"")');
$objConditional1->getStyle()->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);  

$conditionalStyles = $sheet->getStyle('B2')->getConditionalStyles();
array_push($conditionalStyles, $objConditional1);    
$sheet->getStyle('B2')->setConditionalStyles($conditionalStyles);

$sheet->duplicateConditionalStyle(
$sheet->getStyle('B2')->getConditionalStyles(),
    'B3:B9999'
);
  1. I'm not sure I understand how to add this condition to every single row and column after row 2...
  2. Second of all, the border is not being added as expected... In excel the formatting says (none)...

Can I have some help with this?

The goal is to look like this: enter image description here

Upvotes: 0

Views: 3089

Answers (1)

Jimmyt1988
Jimmyt1988

Reputation: 21176

The addition is in the last line! Did the job.. ta da

$objConditional1 = new PHPExcel_Style_Conditional();
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION)
                ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_EQUAL)
                ->addCondition('AND((B2<>B3),B2<>"")');
$objConditional1->getStyle()->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);  

$conditionalStyles = $sheet->getStyle('B2')->getConditionalStyles();
array_push($conditionalStyles, $objConditional1);    
$sheet->getStyle('A$2:$U$10000')->setConditionalStyles($conditionalStyles);

Upvotes: 2

Related Questions