| 
									
										
										
										
											2020-01-04 17:50:04 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace PhpOffice\PhpSpreadsheetTests\Reader; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\IOFactory; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Shared\File; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Style\Color; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Style\Conditional; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Style\Fill; | 
					
						
							|  |  |  | use PHPUnit\Framework\TestCase; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Xlsx2Test extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-05-18 04:49:57 +00:00
										 |  |  |     public function testLoadXlsxConditionalFormatting2(): void | 
					
						
							| 
									
										
										
										
											2020-01-04 17:50:04 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         // Make sure Conditionals are read correctly from existing file
 | 
					
						
							| 
									
										
										
										
											2020-05-17 09:35:55 +00:00
										 |  |  |         $filename = 'tests/data/Reader/XLSX/conditionalFormatting2Test.xlsx'; | 
					
						
							| 
									
										
										
										
											2020-01-04 17:50:04 +00:00
										 |  |  |         $reader = IOFactory::createReader('Xlsx'); | 
					
						
							|  |  |  |         $spreadsheet = $reader->load($filename); | 
					
						
							|  |  |  |         $worksheet = $spreadsheet->getActiveSheet(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $conditionalStyle = $worksheet->getConditionalStyles('A2:A8'); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditionalStyle); | 
					
						
							|  |  |  |         $conditionalRule = $conditionalStyle[0]; | 
					
						
							|  |  |  |         $conditions = $conditionalRule->getConditions(); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditions); | 
					
						
							|  |  |  |         self::assertEquals(Conditional::CONDITION_NOTCONTAINSBLANKS, $conditionalRule->getConditionType()); | 
					
						
							|  |  |  |         self::assertEquals('LEN(TRIM(A2))>0', $conditions[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $conditionalStyle = $worksheet->getConditionalStyles('B2:B8'); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditionalStyle); | 
					
						
							|  |  |  |         $conditionalRule = $conditionalStyle[0]; | 
					
						
							|  |  |  |         $conditions = $conditionalRule->getConditions(); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditions); | 
					
						
							|  |  |  |         self::assertEquals(Conditional::CONDITION_CONTAINSBLANKS, $conditionalRule->getConditionType()); | 
					
						
							|  |  |  |         self::assertEquals('LEN(TRIM(B2))=0', $conditions[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $conditionalStyle = $worksheet->getConditionalStyles('C2:C8'); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditionalStyle); | 
					
						
							|  |  |  |         $conditionalRule = $conditionalStyle[0]; | 
					
						
							|  |  |  |         $conditions = $conditionalRule->getConditions(); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditions); | 
					
						
							|  |  |  |         self::assertEquals(Conditional::CONDITION_CELLIS, $conditionalRule->getConditionType()); | 
					
						
							|  |  |  |         self::assertEquals(Conditional::OPERATOR_GREATERTHAN, $conditionalRule->getOperatorType()); | 
					
						
							|  |  |  |         self::assertEquals('5', $conditions[0]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 04:49:57 +00:00
										 |  |  |     public function testReloadXlsxConditionalFormatting2(): void | 
					
						
							| 
									
										
										
										
											2020-01-04 17:50:04 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         // Make sure conditionals from existing file are maintained across save
 | 
					
						
							| 
									
										
										
										
											2020-05-17 09:35:55 +00:00
										 |  |  |         $filename = 'tests/data/Reader/XLSX/conditionalFormatting2Test.xlsx'; | 
					
						
							| 
									
										
										
										
											2020-01-04 17:50:04 +00:00
										 |  |  |         $outfile = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test'); | 
					
						
							|  |  |  |         $reader = IOFactory::createReader('Xlsx'); | 
					
						
							|  |  |  |         $spreadshee1 = $reader->load($filename); | 
					
						
							|  |  |  |         $writer = IOFactory::createWriter($spreadshee1, 'Xlsx'); | 
					
						
							|  |  |  |         $writer->save($outfile); | 
					
						
							|  |  |  |         $spreadsheet = $reader->load($outfile); | 
					
						
							| 
									
										
										
										
											2020-05-24 11:03:07 +00:00
										 |  |  |         unlink($outfile); | 
					
						
							| 
									
										
										
										
											2020-01-04 17:50:04 +00:00
										 |  |  |         $worksheet = $spreadsheet->getActiveSheet(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $conditionalStyle = $worksheet->getConditionalStyles('A2:A8'); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditionalStyle); | 
					
						
							|  |  |  |         $conditionalRule = $conditionalStyle[0]; | 
					
						
							|  |  |  |         $conditions = $conditionalRule->getConditions(); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditions); | 
					
						
							|  |  |  |         self::assertEquals(Conditional::CONDITION_NOTCONTAINSBLANKS, $conditionalRule->getConditionType()); | 
					
						
							|  |  |  |         self::assertEquals('LEN(TRIM(A2:A8))>0', $conditions[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $conditionalStyle = $worksheet->getConditionalStyles('B2:B8'); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditionalStyle); | 
					
						
							|  |  |  |         $conditionalRule = $conditionalStyle[0]; | 
					
						
							|  |  |  |         $conditions = $conditionalRule->getConditions(); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditions); | 
					
						
							|  |  |  |         self::assertEquals(Conditional::CONDITION_CONTAINSBLANKS, $conditionalRule->getConditionType()); | 
					
						
							|  |  |  |         self::assertEquals('LEN(TRIM(B2:B8))=0', $conditions[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $conditionalStyle = $worksheet->getConditionalStyles('C2:C8'); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditionalStyle); | 
					
						
							|  |  |  |         $conditionalRule = $conditionalStyle[0]; | 
					
						
							|  |  |  |         $conditions = $conditionalRule->getConditions(); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditions); | 
					
						
							|  |  |  |         self::assertEquals(Conditional::CONDITION_CELLIS, $conditionalRule->getConditionType()); | 
					
						
							|  |  |  |         self::assertEquals(Conditional::OPERATOR_GREATERTHAN, $conditionalRule->getOperatorType()); | 
					
						
							|  |  |  |         self::assertEquals('5', $conditions[0]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 04:49:57 +00:00
										 |  |  |     public function testNewXlsxConditionalFormatting2(): void | 
					
						
							| 
									
										
										
										
											2020-01-04 17:50:04 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         // Make sure blanks/non-blanks added by PhpSpreadsheet are handled correctly
 | 
					
						
							|  |  |  |         $outfile = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test'); | 
					
						
							|  |  |  |         $spreadshee1 = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); | 
					
						
							|  |  |  |         $sheet = $spreadshee1->getActiveSheet(); | 
					
						
							|  |  |  |         $sheet->setCellValue('A2', 'a2'); | 
					
						
							|  |  |  |         $sheet->setCellValue('A4', 'a4'); | 
					
						
							|  |  |  |         $sheet->setCellValue('A6', 'a6'); | 
					
						
							|  |  |  |         $cond1 = new Conditional(); | 
					
						
							|  |  |  |         $cond1->setConditionType(Conditional::CONDITION_CONTAINSBLANKS); | 
					
						
							|  |  |  |         $cond1->getStyle()->getFill()->setFillType(Fill::FILL_SOLID); | 
					
						
							|  |  |  |         $cond1->getStyle()->getFill()->getEndColor()->setARGB(Color::COLOR_RED); | 
					
						
							|  |  |  |         $cond = [$cond1]; | 
					
						
							|  |  |  |         $sheet->getStyle('A1:A6')->setConditionalStyles($cond); | 
					
						
							|  |  |  |         $writer = IOFactory::createWriter($spreadshee1, 'Xlsx'); | 
					
						
							|  |  |  |         $writer->save($outfile); | 
					
						
							|  |  |  |         $reader = IOFactory::createReader('Xlsx'); | 
					
						
							|  |  |  |         $spreadsheet = $reader->load($outfile); | 
					
						
							| 
									
										
										
										
											2020-05-24 11:03:07 +00:00
										 |  |  |         unlink($outfile); | 
					
						
							| 
									
										
										
										
											2020-01-04 17:50:04 +00:00
										 |  |  |         $worksheet = $spreadsheet->getActiveSheet(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $conditionalStyle = $worksheet->getConditionalStyles('A1:A6'); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditionalStyle); | 
					
						
							|  |  |  |         $conditionalRule = $conditionalStyle[0]; | 
					
						
							|  |  |  |         $conditions = $conditionalRule->getConditions(); | 
					
						
							|  |  |  |         self::assertNotEmpty($conditions); | 
					
						
							|  |  |  |         self::assertEquals(Conditional::CONDITION_CONTAINSBLANKS, $conditionalRule->getConditionType()); | 
					
						
							|  |  |  |         self::assertEquals('LEN(TRIM(A1:A6))=0', $conditions[0]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |