2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								<?php
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use PhpOffice\PhpSpreadsheet\Spreadsheet;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use PhpOffice\PhpSpreadsheet\Style\Color;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use PhpOffice\PhpSpreadsheet\Style\Conditional;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-01 08:48:59 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								require __DIR__ . '/../Header.php';
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Create new Spreadsheet object
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$helper->log('Create new Spreadsheet object');
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$spreadsheet = new Spreadsheet();
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Set document properties
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$helper->log('Set document properties');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ->setLastModifiedBy('Maarten Balliauw')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ->setTitle('Office 2007 XLSX Test Document')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ->setSubject('Office 2007 XLSX Test Document')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ->setKeywords('office 2007 openxml php')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ->setCategory('Test result file');
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Create a first sheet, representing sales data
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$helper->log('Add some data');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->setActiveSheetIndex(0);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->setCellValue('A1', 'Description')
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ->setCellValue('B1', 'Amount');
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->setCellValue('A2', 'Paycheck received')
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ->setCellValue('B2', 100);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->setCellValue('A3', 'Cup of coffee bought')
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ->setCellValue('B3', -1.5);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->setCellValue('A4', 'Cup of coffee bought')
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ->setCellValue('B4', -1.5);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->setCellValue('A5', 'Cup of tea bought')
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ->setCellValue('B5', -1.2);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->setCellValue('A6', 'Found some money')
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ->setCellValue('B6', 8);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->setCellValue('A7', 'Total:')
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ->setCellValue('B7', '=SUM(B2:B6)');
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Set column widths
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$helper->log('Set column widths');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->getColumnDimension('A')->setWidth(30);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->getColumnDimension('B')->setWidth(12);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Add conditional formatting
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$helper->log('Add conditional formatting');
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$conditional1 = new Conditional();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$conditional1->setConditionType(Conditional::CONDITION_CELLIS)
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ->setOperatorType(Conditional::OPERATOR_BETWEEN)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ->addCondition('200')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ->addCondition('400');
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$conditional1->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_YELLOW);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$conditional1->getStyle()->getFont()->setBold(true);
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$conditional1->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$conditional2 = new Conditional();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$conditional2->setConditionType(Conditional::CONDITION_CELLIS)
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ->setOperatorType(Conditional::OPERATOR_LESSTHAN)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ->addCondition('0');
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$conditional2->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_RED);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$conditional2->getStyle()->getFont()->setItalic(true);
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$conditional2->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$conditional3 = new Conditional();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$conditional3->setConditionType(Conditional::CONDITION_CELLIS)
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ->setOperatorType(Conditional::OPERATOR_GREATERTHANOREQUAL)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ->addCondition('0');
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$conditional3->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_GREEN);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$conditional3->getStyle()->getFont()->setItalic(true);
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$conditional3->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('B2')->getConditionalStyles();
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-19 02:07:31 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$conditionalStyles[] = $conditional1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$conditionalStyles[] = $conditional2;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$conditionalStyles[] = $conditional3;
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->getStyle('B2')->setConditionalStyles($conditionalStyles);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//	duplicate the conditional styles across a range of cells
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$helper->log('Duplicate the conditional formatting across a range of cells');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->duplicateConditionalStyle(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $spreadsheet->getActiveSheet()->getStyle('B2')->getConditionalStyles(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    'B3:B7'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Set fonts
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$helper->log('Set fonts');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->getStyle('A1:B1')->getFont()->setBold(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//$spreadsheet->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->getStyle('A7:B7')->getFont()->setBold(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//$spreadsheet->getActiveSheet()->getStyle('B7')->getFont()->setBold(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Set header and footer. When no different headers for odd/even are used, odd header is assumed.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$helper->log('Set header/footer');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&BPersonal cash register&RPrinted on &D');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $spreadsheet->getProperties()->getTitle() . '&RPage &P of &N');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Set page orientation and size
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$helper->log('Set page orientation and size');
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_PORTRAIT);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(PageSetup::PAPERSIZE_A4);
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Rename worksheet
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$helper->log('Rename worksheet');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$spreadsheet->getActiveSheet()->setTitle('Invoice');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Save
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$helper->write($spreadsheet, __FILE__);
							 |