Conditional formatting damage styles - phpexcel-94877

Topics: Developer Forum
Oct 10, 2012 at 6:54 PM
Edited Oct 10, 2012 at 6:56 PM

 

This is simple example:

$objPHPExcel = new PHPExcel(); $styles = array(); $styles['percent'] = new PHPExcel_Style(); $styles['percent']->applyFromArray(array ( 'numberformat' => array ( 'code' => '#0.00%' ) )); $styles['currency'] = new PHPExcel_Style(); $styles['currency']->applyFromArray(array ( 'numberformat' => array ( 'code' => '[$$-409]#,##0.00;-[$$-409]#,##0.00' ) )); $sheet = $objPHPExcel->createSheet(); $sheet->setCellValue('A1', 10.10); $sheet->setCellValue('B1', 10.10); $sheet->setSharedStyle($styles['percent'], 'A1'); $sheet->setSharedStyle($styles['currency'], 'B1'); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->setCellValue('A2', 'Paycheck received'); $objPHPExcel->getActiveSheet()->setCellValue('B2', 100); $objConditional1 = new PHPExcel_Style_Conditional(); $objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS); $objConditional1->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_BETWEEN); $objConditional1->addCondition('200'); $objConditional1->addCondition('400'); $objConditional1->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_YELLOW); $objConditional1->getStyle()->getFont()->setBold(true); $objConditional1->getStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); $conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('B2')->getConditionalStyles(); array_push($conditionalStyles, $objConditional1); $objPHPExcel->getActiveSheet()->getStyle('B2')->setConditionalStyles($conditionalStyles); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save(str_replace('.php', '.xlsx', __FILE__));


Expected Worksheet 1!A1 percent format, but I get euro format.