简体   繁体   English

获取PhpExcel中的单元格背景颜色

[英]Get the cell background color in PhpExcel

I'm using Excel5 in my project. 我在我的项目中使用Excel5。 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. getStartColor()总是为getEndColor()而不是红色返回FFFFFFFFFF000000

I don't know what am missing. 我不知道遗失了什么。 Can any one help me in figuring this out? 任何人都可以帮我解决这个问题吗?

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(TRUE)表示只读取单元格中的数据 ,但没有任何样式...作为样式的一部分,读者在加载文件时会忽略背景颜色...如果填充样式不是加载,然后调用$ objPHPExcel-> getActiveSheet() - > getStyle('A1') - > getFill()将返回默认的填充样式和颜色。

Load the file with setReadDataOnly(FALSE) and you should find it works 使用setReadDataOnly(FALSE)加载文件,你会发现它有效

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. 这超出了PHPExcel的范围....所有内容都通过DDE填充,包括大部分样式,因此底层填充颜色是普通的(由PHPExcel getFill颜色调用返回),直到外部可执行文件TOS.exe填充数据并相应地设置样式。 Your only option here is to use COM so that the workbook is being executed in MS Excel itself. 这里唯一的选择是使用COM,以便在MS Excel本身中执行工作簿。

Your second code: 你的第二个代码:

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

Works , it just returns a color hex code (FF0000). Works,它只返回一个颜色十六进制代码(FF0000)。

RGB = Red Blue Green = xx xx xx RGB =红蓝绿= xx xx xx

FF0000 is actually RED. FF0000实际上是RED。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM