Get the cell background color in PhpExcel

回眸只為那壹抹淺笑 提交于 2019-12-23 14:03:05

问题


I'm 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 are returning wrong color. The getStartColor() always returning FFFFFFFF and FF000000 for getEndColor() instead of red.

I don't know what am missing. Can any one help me in figuring this out?


回答1:


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

Load the file with setReadDataOnly(FALSE) and you should find it works

EDIT

This is way beyond the scope of PHPExcel.... everything is populated via DDE, including most of the styling, so the underlying fill colour is plain (as returned by the PHPExcel getFill colour call) until the external executable TOS.exe populates the data and sets the styles accordingly. Your only option here is to use COM so that the workbook is being executed in MS Excel itself.




回答2:


Your second code:

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

Works , it just returns a color hex code (FF0000).

RGB = Red Blue Green = xx xx xx

FF0000 is actually RED.



来源:https://stackoverflow.com/questions/12113520/get-the-cell-background-color-in-phpexcel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!