unable to set certain Fill colors

Topics: Developer Forum, User Forum
Apr 15, 2011 at 6:55 PM

Hi all,

I am trying to set a particular color with a solid fill on a cell but when I print the sheet, the background fill color is still white. What's strange is that background fill works for other colors.

Here is the sample code I am trying out:

$objPHPExcel = new PHPExcel();

// This works fine
$fill = array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => 'DADADA') );
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0,1, 'Works!');

// This doesn't work. Why? 
$fill = array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => 'E6E6FA') );
// echo $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(0,2)->getFill()->getStartColor()->getRGB(); // Prints E6E6FA
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0,2, 'doesnt Work!');

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);


Thanks for all the help!

Apr 18, 2011 at 7:55 PM

Hello revdev,

I have tried your code and it works correctly for me.

You can access here

result https://docs.google.com/leaf?id=0BxQqT5DtCtNTYmQ5M2E1YmItYjY2MC00MTA5LWJjOWYtMmZlNjRlYWEyNWJk&hl=en

the result, on my Microsoft Excel 2010 it renders to the correct color. What is exactly the problem?

Apr 20, 2011 at 11:24 PM

Oh I think I got the issue but not sure how to solve it.

The color I am trying to set is unavailable in the default palette of my excel reader (MS Excel 2008 for mac, ver 12.2.0)... Any idea how I can use custom colors which are not in the palette? 

thanks a lot!