7

I am using PHPExcel project, but I am having a question in mind, and without solution on the earth.

I had googled for this question for a while, but I CAN NOT find a way to get a CELL BACKGROUND COLOR!

I tried to use the method 'getColor()' or what ... it doesn't work or just shows the warning message...

Can somebody please tell me how to get a CELL COLOR using PHPExcel? THANKS

pnuts
  • 58,317
  • 11
  • 87
  • 139
Jarkid
  • 171
  • 1
  • 4
  • 13

3 Answers3

21
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->getARGB();

or

$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->getRGB();
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • 3
    This does not work when `$objPHPExcel->setReadDataOnly(true);` and it would always return `FFFFFF` whatever color it has. – Sithu Jul 16 '16 at 07:39
  • 6
    @Sithu - yes, if you explicitly tell PHPExcel not to read the style information, then you won't be able to get that information subsequently.... that seems pretty logical to me – Mark Baker Jul 16 '16 at 09:21
  • @Sithu thank you! your comment should be more visible for others having the same problem – pmiguelpinto90 Aug 08 '18 at 14:16
0

to set background for specific cells.it's works for me

$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' =>'FF1E1E')
Elango Mani
  • 354
  • 4
  • 21