From 17cb1fdc7cda57e1eb91dba68e903d99b55ed39d Mon Sep 17 00:00:00 2001 From: David Date: Thu, 18 Jan 2018 18:29:59 +0100 Subject: [PATCH] Added conditionnal formatting --- modules/ant_wp/GenerateWp.php | 65 +++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/modules/ant_wp/GenerateWp.php b/modules/ant_wp/GenerateWp.php index 99f356d4..63dd6d24 100644 --- a/modules/ant_wp/GenerateWp.php +++ b/modules/ant_wp/GenerateWp.php @@ -9,7 +9,7 @@ class GenerateWp public function __construct() { - //@ini_set('display_errors', 'on'); + @ini_set('display_errors', 'on'); $this->objPHPExcel = new PHPExcel(); $this->columns_es = array( 'B' => 'EAN', @@ -76,6 +76,9 @@ class GenerateWp public static $FORMAT_DARK_BLUE = '214A7B'; public static $FORMAT_LIGHT_BLUE = '6C8DCD'; public static $FORMAT_LIGHTER_DARK_BLUE = 'C6D9F0'; + public static $FORMAT_BG_LIGHT_RED = 'FEC7CE'; + public static $FORMAT_BG_LIGHT_GREEN = 'C7EECF'; + public static $FORMAT_BG_LIGHT_YELLOW = 'FEEAA0'; public function generate($params) { @@ -515,16 +518,64 @@ class GenerateWp $this->objPHPExcel->getActiveSheet() ->getStyle('AL5:AL' . $lastLine) ->getFont()->setBold(true); - //Conditionnal formating - /*$objConditional1 = new PHPExcel_Style_Conditional(); + //Conditionnal formating for column L + $nb_max_char = 64; + $objConditional1 = new PHPExcel_Style_Conditional(); $objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) - ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_EQUAL) - ->addCondition(17); - $objConditional1->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(PHPExcel_Style_Color::COLOR_GREEN); + ->addCondition('L5>'.$nb_max_char); + $objConditional1->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_RED); + $objConditional2 = new PHPExcel_Style_Conditional(); + $objConditional2->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) + ->addCondition('L5='.$nb_max_char); + $objConditional2->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_YELLOW); + $objConditional3 = new PHPExcel_Style_Conditional(); + $objConditional3->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) + ->addCondition('L5<'.$nb_max_char); + $objConditional3->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_GREEN); + + $conditionalStyles = $this->objPHPExcel->getActiveSheet()->getStyle('L5:L'.$lastLine)->getConditionalStyles(); + $conditionalStyles[] = $objConditional1; + $conditionalStyles[] = $objConditional2; + $conditionalStyles[] = $objConditional3; + $this->objPHPExcel->getActiveSheet()->getStyle('L5:L'.$lastLine)->setConditionalStyles($conditionalStyles); + + $nb_max_char = 17; + //Conditionnal formating for column T + $objConditional1 = new PHPExcel_Style_Conditional(); + $objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) + ->addCondition('T5>'.$nb_max_char); + $objConditional1->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_RED); + $objConditional2 = new PHPExcel_Style_Conditional(); + $objConditional2->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) + ->addCondition('T5='.$nb_max_char); + $objConditional2->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_YELLOW); + $objConditional3 = new PHPExcel_Style_Conditional(); + $objConditional3->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) + ->addCondition('T5<'.$nb_max_char); + $objConditional3->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_GREEN); $conditionalStyles = $this->objPHPExcel->getActiveSheet()->getStyle('T5:T'.$lastLine)->getConditionalStyles(); $conditionalStyles[] = $objConditional1; - $this->objPHPExcel->getActiveSheet()->getStyle('T5:T'.$lastLine)->setConditionalStyles($conditionalStyles);*/ + $conditionalStyles[] = $objConditional2; + $conditionalStyles[] = $objConditional3; + $this->objPHPExcel->getActiveSheet()->getStyle('T5:T'.$lastLine)->setConditionalStyles($conditionalStyles); + + //Conditionnal formating for column AJ + $objConditional1 = new PHPExcel_Style_Conditional(); + $objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT) + ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_CONTAINSTEXT) + ->setText('ATTENTION'); + $objConditional1->getStyle()->getFont()->setColor(new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_RED)); + $objConditional2 = new PHPExcel_Style_Conditional(); + $objConditional2->setConditionType(PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT) + ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_CONTAINSTEXT) + ->setText('COOL'); + $objConditional2->getStyle()->getFont()->setColor(new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_GREEN)); + + $conditionalStyles = $this->objPHPExcel->getActiveSheet()->getStyle('AJ5:AJ'.$lastLine)->getConditionalStyles(); + $conditionalStyles[] = $objConditional1; + $conditionalStyles[] = $objConditional2; + $this->objPHPExcel->getActiveSheet()->getStyle('AJ5:AJ'.$lastLine)->setConditionalStyles($conditionalStyles); $this->objPHPExcel->getActiveSheet() ->getStyle('AH5:AH'.$lastLine)