我有一张纸张拉取值基于
if ($slaHours >= 0 & $slaHours <= 72)
我想要做的是设置这些值的颜色,如果值小于12.我仍然想显示大于12且小于72的值,所以我尝试的代码是
$styleArray = array(
'font' => array(
'bold' => true,
'color' => array('rgb' => 'FF0000'),
));
if ($slaHours >= 0 & $slaHours <= 72)
$slaHours = $objWorksheet->getCellByColumnAndRow(3, $row)->getValue();
if($slaHours <=12) {
$slaHours = $objWorksheet->getCellByColumnAndRow(3, $row)->getValue()->applyFromArray($styleArray);
但是,我得到一个致命的错误
“Call to a member function applyFromArray() on a non-object “
这个PHP的东西很新,所以非常感谢任何有助于这项工作的帮助.
谢谢
解决方法:
applyFromArray()是PHPExcel_Cell对象的一个方法,而不是单元格值(除非单元格包含富文本,这是一个简单的PHP数据类型)….所以你需要针对单元格调用它
$objWorksheet->getCellByColumnAndRow(3, $row)->applyFromArray;
但是如果你需要一个基于单元格值的样式,那么你应该使用条件样式.有关详细信息,请参阅开发人员文档的4.6.23节(“条件格式化单元格”),并查看示例中的08conditionalformatting.php
编辑
$objConditionalStyle = new PHPExcel_Style_Conditional();
$objConditionalStyle->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_LESSTHAN)
->addCondition('12');
$objConditionalStyle->getStyle()->getFont()->getColor()->setRGB('FF0000');
$objConditionalStyle->getStyle()->getFont()->setBold(true);
$conditionalStyles = $objWorksheet->getStyle('A3')
->getConditionalStyles();
array_push($conditionalStyles, $objConditionalStyle);
$objPHPExcel->getActiveSheet()->getStyle('A3')
->setConditionalStyles($conditionalStyles);