Reputation: 508
My conditional formatting is off by one row for some reason and I cannot figure out why.
Here is the code:
$conditional = new PHPExcel_Style_Conditional();
$conditional->setConditionType(PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT);
$conditional->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_CONTAINSTEXT);
$conditional->setText('~?');
$conditional->getStyle()->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'endcolor' => array('rgb' => '7FA0D1')));
...
$conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('A:J')->getConditionalStyles();
array_push($conditionalStyles, $conditional);
$objPHPExcel->getActiveSheet()->getStyle('A:J')->setConditionalStyles($conditionalStyles);
In the spreadsheet that this generates, I have
?
A
And for some reason it formats the A instead of the ? above it. If I go into Excel's conditional formatting "Manage Rules", select this rule, "Edit Rule", click "Ok" without changing anything, then click "Ok" in the main window, it fixes itself. So I'm not sure why its off on the first load?
Upvotes: 0
Views: 1644
Reputation: 212522
Row and column styles aren't supported in PHPExcel, so a range of 'A:J'
in your getStyle call is invalid. Only cell styles are supported, so instead, you need to specify a range of cells
e.g
$conditionalStyles = $objPHPExcel
->getActiveSheet()
->getStyle('A1024:J1024')
->getConditionalStyles();
Upvotes: 1