PHPOffice / PHPExcel

ARCHIVED
Other
11.46k stars 4.19k forks source link

Conditional formating in Excel5 #189

Open mzeddd opened 11 years ago

mzeddd commented 11 years ago

In changelog.txt I see that it should be working now.

I tried to apply it with % format, i.e. with ranges like 0.1-0.5; 0.5-0.9, ...

$objConditional1 = new PHPExcel_Style_Conditional(); $objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS) ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_BETWEEN) ->addCondition('0.1') ->addCondition('0.5'); $objConditional1->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED);

Result: It is not working. When I open conditional formating window in Excel both values above set to zero '0'.

MarkBaker commented 11 years ago

Try using 0.1 and 0.5 rather than '0.1' and '0.5'

mzeddd commented 11 years ago

Still the same problem even with 0.1 instead of '0.1'

ArvidEnbom commented 8 years ago

I'm having the same problem

Trying to write a condition that will highlight the whole row red if the cell begins with a "-". I tried the expression manually inside an excel document first, and it worked fine. When I went to implement the same condition in PHPExcel, I couldn't get it to work. I've tried copying many snippets posted by other users across the internet, and I couldn't get a single one of them to work. Many, many hours later, I've now given up hope and I'm resorting to posting this in the hopes that you can help me. I hope it's just something stupid I did wrong.

Relevant code:

        $objConditional1 = new PHPExcel_Style_Conditional();
        $objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION);
        $objConditional1->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_EQUAL);
        $objConditional1->addCondition('LEFT(J2)="-"');
        $objConditional1->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('C00000');
        $objConditional1->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setRGB('C00000');

        $sheet->duplicateConditionalStyle(
                array($objConditional1), 
                'A2:J'.$excel_row
            );

Result: phpexcel not working

as you can see, the expression is not saved at all (instead it just inserts "=0"), and the background color remains unchanged. You may have noticed I tried setting both the "Start" color and the "End" color (not sure what the difference is there).