如果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);
       }
   }

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...