Get cell background color in PhpExcel

I am using Excel5 in my project. I have already tried the following codes:

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

and

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

but these codes return the wrong color. getStartColor() always returns FFFFFFFF and FF000000 for getEndColor() instead of red.

I don’t know what is missing. Can someone help me figure this out?

+4
source share
2 answers

setReadDataOnly (TRUE) means only reading data from cells, but none of the styles ... and as background colors are not part of the style, the reader will ignore the background colors when it loads the file ... if the fill style is not loaded, then call $ objPHPExcel-> getActiveSheet () β†’ getStyle ('A1') β†’ getFill () will return the default fill style and colors.

Download the file using setReadDataOnly (FALSE) and you should find its work

EDIT

This is beyond the scope of PHPExcel .... everything is populated using DDE, including most of the style, so the primary fill color is simple (as returned by the PHP call toExcel getFill) to an external TOS executable. exe fills in the data and sets styles accordingly. Your only option here is to use COM so that the workbook runs in MS Excel itself.

+7
source

Second code:

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

It works, it just returns the hex color code (FF0000).

RGB = Red Blue Green = xx xx xx

FF0000 is really RED.

+1
source

All Articles