Added conditionnal formatting

This commit is contained in:
David 2018-01-18 18:29:59 +01:00
parent f52f89ad64
commit 17cb1fdc7c

View File

@ -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)