2

I have a cell that has conditional formatting applied and a static color (green). The cell is red, if you view it in Excel (because of conditional formatting). If I use getStartColor(), I get the static color: green. If I use getEndColor() I get white. I'd like to get the red one.

How can I do that?

duality_
  • 17,738
  • 23
  • 77
  • 95
  • Start here http://stackoverflow.com/questions/996384/excel-2007-conditional-formatting-how-to-get-cell-color and also http://stackoverflow.com/questions/7408899/how-do-i-find-the-fill-colour-value-of-a-conditionally-formatted-cell-in-excel-2 – David Zemens May 09 '13 at 18:06
  • Are you using getStartColor() on the cells' style or on the conditional style? – Mark Baker May 09 '13 at 20:09
  • @DavidZemens: I'm talking about PHPExcel, not just Excel. – duality_ May 10 '13 at 08:49
  • @Mark yeah, on the style, not the conditional style. Will read your answer now. – duality_ May 10 '13 at 08:50

1 Answers1

3
$conditionalStyles = $objPHPExcel->getActiveSheet()
    ->getStyle('B2')
    ->getConditionalStyles();

will return the conditional styles for the specified cell as an array:

You can loop through those, using getConditionType(), getOperatorType() and getConditions() (which can return an array of conditions) , etc to identify the conditional rule, test if the cell value matches that rule, and then use getStyle() to retrieve the style details

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • Huh, this looks like a lot of work. Maybe this can be integrated into PHPExcel? This conditions can sometimes be very complex... – duality_ May 10 '13 at 09:22
  • 2
    Possibly, in PHPExcel 2.0.0 - I'll look at the options, because it would also be potentially useful for the HTML and PDF Writers. Note that Conditional styles will be changing (internally) within PHPExcel for the 2.0.0 version anyway, as we're looking at allowing a single style to be set for multiple cells without needing to clone the conditional – Mark Baker May 10 '13 at 09:24