Problem using Conditional Styles

Topics: User Forum
Sep 5, 2011 at 9:29 PM

Using PHP 5.2.12 and PHPExcel 1.7.6

I'm trying to create zebra stripes accross a range, but I cannot seem to control the color of the fill. Here is my code:

$objPHPExcel = new PHPExcel();

		$objConditional1 = new PHPExcel_Style_Conditional();
			$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION);
			$objConditional1->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_NONE);
			$objConditional1->setCondition( 'MOD(ROW(),2)=0');

			$objConditional1->getStyle( 'A2:L47' )->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB( 'FFFDE9D9' );


$conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('A2:L47')->getConditionalStyles();
array_push($conditionalStyles, $objConditional1);
$objPHPExcel->getActiveSheet()->getStyle('A2:L47' )->setConditionalStyles($conditionalStyles);


header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="myfile.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output'); 

In the output is solid black stripes. No matter what I set the argb to in setARGB() all I get is black. Any ideas?

Nov 25, 2011 at 12:57 PM

Try usin this expresion:

$objConditional1->getStyle( 'A2:L47' )->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB( 'FFFDE9D9' );