getActiveSheet(); $sheet->setTitle('2010'); $sheet = $workbook->createSheet(); $sheet->setTitle('2013'); $sheet = $workbook->createSheet(); $sheet->setTitle('2016'); $sheet = $workbook->createSheet(); $sheet->setTitle('2019'); foreach ($formulas as $values) { $sheet = $workbook->setActiveSheetIndexByName($values[0]); $sheet->setCellValue($values[1], $values[2]); } $sheet = $workbook->setActiveSheetIndexByName('2013'); $sheet->getStyle('A3:A5')->getNumberFormat()->setFormatCode('yyyy-mm-dd'); $sheet->getColumnDimension('A')->setAutoSize(true); $condition0 = new Conditional(); $condition0->setConditionType(Conditional::CONDITION_EXPRESSION); $condition0->addCondition('ABS(B3)<2'); $condition0->getStyle()->getFill()->setFillType(Fill::FILL_SOLID); $condition0->getStyle()->getFill()->getEndColor()->setARGB(Color::COLOR_RED); $condition1 = new Conditional(); $condition1->setConditionType(Conditional::CONDITION_EXPRESSION); $condition1->addCondition('ABS(B3)>2'); $condition1->getStyle()->getFill()->setFillType(Fill::FILL_SOLID); $condition1->getStyle()->getFill()->getEndColor()->setARGB(Color::COLOR_GREEN); $cond = [$condition0, $condition1]; $sheet->getStyle('B3:B5')->setConditionalStyles($cond); $condition0 = new Conditional(); $condition0->setConditionType(Conditional::CONDITION_EXPRESSION); $condition0->addCondition('ISOWEEKNUM(A3)<10'); $condition0->getStyle()->getFill()->setFillType(Fill::FILL_SOLID); $condition0->getStyle()->getFill()->getEndColor()->setARGB(Color::COLOR_RED); $condition1 = new Conditional(); $condition1->setConditionType(Conditional::CONDITION_EXPRESSION); $condition1->addCondition('ISOWEEKNUM(A3)>40'); $condition1->getStyle()->getFill()->setFillType(Fill::FILL_SOLID); $condition1->getStyle()->getFill()->getEndColor()->setARGB(Color::COLOR_GREEN); $cond = [$condition0, $condition1]; $sheet->getStyle('A3:A5')->setConditionalStyles($cond); $sheet->setSelectedCell('B1'); $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($workbook, 'Xlsx'); $oufil = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test'); $writer->save($oufil); $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx'); $rdobj = $reader->load($oufil); unlink($oufil); foreach ($formulas as $values) { $sheet = $rdobj->setActiveSheetIndexByName($values[0]); self::assertEquals($values[3], $sheet->getCell($values[1])->getValue()); if ($values[4] !== null) { self::assertEquals($values[4], $sheet->getCell($values[1])->getCalculatedValue()); } } $sheet = $rdobj->setActiveSheetIndexByName('2013'); $cond = $sheet->getConditionalStyles('A3:A5'); self::assertEquals('_xlfn.ISOWEEKNUM(A3)<10', $cond[0]->getConditions()[0]); self::assertEquals('_xlfn.ISOWEEKNUM(A3)>40', $cond[1]->getConditions()[0]); $cond = $sheet->getConditionalStyles('B3:B5'); self::assertEquals('ABS(B3)<2', $cond[0]->getConditions()[0]); self::assertEquals('ABS(B3)>2', $cond[1]->getConditions()[0]); } }