background color change and excel 2010

Topics: User Forum
Jul 15, 2012 at 12:15 AM
Edited Jul 15, 2012 at 12:21 AM


i have the template

and use the code :

$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load($repertoire_travail_cable."template/rapport cable2.xlsx");
$worksheet = $objPHPExcel->setActiveSheetIndexByName("Cuivre");


$writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

And in the result, the background cell are not keept. and the code :

$worksheet->getStyleByColumnAndRow(0, 2)->getFill()->getStartColor()->setARGB('FF00FF')

doesn't change the background cell as well.

You can see the result

Do you know how can i keep and change the background, on my generated file ?


Jul 15, 2012 at 11:15 AM

It helps to understand that setARGB expects an ARGB (red green blue alpha) colour value,

$worksheet->getStyleByColumnAndRow(0, 2)->getFill()->getStartColor()->setARGB('FFFF00FF')

You're passing an RGB colour value, but PHPExcel doesn't automatically add an alpha channel for you.


setRGB is the method that expects a simple RGB colour value without any alpha channel

$worksheet->getStyleByColumnAndRow(0, 2)->getFill()->getStartColor()->setRGB('FF00FF')

and that will add the alpha channel required to hold the value