如果 B 列的值小于 700,则 phpspreadsheet 条件格式列 A

phpspreadsheet conditional format column A if value of column B is less than 700

目前,我正在 laravel 5.6 中使用 maatwebsite 3.1 导出 excel sheet。 我正在使用 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 < 700,则将 A1 设为红色; 如果 G2 <700 则将 A2 设为红色,依此类推。

请分享相应的条件格式规则

我想通了,

  $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);
       }
   }