Using expression for conditional formatting

Topics: Developer Forum, Project Management Forum, User Forum
Oct 30, 2008 at 11:10 AM
Edited Oct 30, 2008 at 11:11 AM
Hi Everyone,
The conditional formatting now has new constant CONDITION_EXPRESSION, how to use this, I to want apply `between` rule in my application.
Thanks in advance
Developer
Oct 31, 2008 at 11:22 AM
Edited Oct 31, 2008 at 11:29 AM
I'm quite sure that the between is not currently supported in PHPExcel. I created work item for monitoring.
Edit:
http://www.codeplex.com/PHPExcel/WorkItem/View.aspx?WorkItemId=7931

As you suggest, a workaround is to use a formula returning true when the cell value is within a certain interval. It is not so elegant because you are required to know the coordinates of the cell the rule is applied to, but it may work:

$excel = new PHPExcel();
$sheet = $excel->getActiveSheet();

$styleArray = array(
    'font' => array(
        'bold' => true,
        'color' => array(
            'rgb' => 'ff0000',
        ),
    ),
);
$styleConditional = new PHPExcel_Style_Conditional();
$styleConditional->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION);
$styleConditional->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_NONE);
$styleConditional->setCondition('AND(10<=$A$1,$A$1<=20)');
$styleConditional->getStyle()->applyFromArray($styleArray);

$conditionalsStyles[] = $styleConditional;

$sheet->getStyle('A1')->setConditionalStyles($conditionalsStyles);
$sheet->getCell('A1')->setValue(12);

$writer = new PHPExcel_Writer_Excel2007($excel);
$writer->save('test.xlsx');


Oct 31, 2008 at 12:16 PM
Thanks
will not solve my problem, but want to know more about CONDITION_EXPRESSION.