如何解决如果B列的值小于700,则phpspreadsheet条件格式A列
当前,我正在使用Laravel 5.6中的maatwebsite 3.1 export导出Excel工作表。 我正在使用phpspreadsheet概念进行条件格式
$conditional_fico = new \PhpOffice\PhpSpreadsheet\Style\Conditional();
$conditional_fico->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS)
->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN)
->addCondition('700');
$conditional_fico->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
$conditionalStyles = $event->sheet->getStyle('G:G')->getConditionalStyles();
$conditionalStyles[] = $conditional_fico;
$event->sheet->getStyle('G:G')->setConditionalStyles($conditionalStyles);
现在,如果各自的G:G小于700,我想更改A:A的颜色。 例子:
如果G1
请分享相应的条件格式设置规则
解决方法
我知道了,
$styleArray = array(
'font' => array(
// 'bold' => true,'color' => array('rgb' => 'FF0000'),));
$highestRow = $event->sheet->getHighestRow();
$highestColumn = $event->sheet->getHighestColumn();
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn);
for ($row = 3; $row <= $highestRow; ++$row) {
$slaHours = $event->sheet->getCellByColumnAndRow(7,$row)->getValue();
if( $slaHours < 700) {
$event->sheet->getCellByColumnAndRow(2,$row)->getStyle()->applyFromArray($styleArray);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。