在PhpExcel中获取单元格背景色
我在项目中使用Excel5.我已经尝试过以下代码:
I'm using Excel5 in my project. I have already tried the following codes:
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->getARGB();
和
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->getEndColor()->getARGB();
,但是这些代码返回错误的颜色. getStartColor()
始终为getEndColor()
返回FFFFFFFF
和FF000000
而不是红色.
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?
setReadDataOnly(TRUE)表示仅读取单元格中的 数据 ,但不读取任何样式. ..并且背景颜色是样式的一部分,读者在加载文件时将忽略背景颜色...如果未加载填充样式,则对$ objPHPExcel-> getActiveSheet()-> getStyle('A1的调用')-> getFill()将返回默认的填充样式和颜色.
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.
使用setReadDataOnly(FALSE)加载文件,您应该会发现它可以正常工作
Load the file with setReadDataOnly(FALSE) and you should find it works
编辑
这超出了PHPExcel的范围....所有内容都是通过DDE填充的,包括大多数样式,因此底层填充颜色是纯色的(由PHPExcel getFill颜色调用返回),直到外部可执行文件TOS为止. exe会填充数据并相应地设置样式.您唯一的选择是使用COM,以便在MS Excel本身中执行工作簿.
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.