2016-08-31 16:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
2017-05-17 22:02:17 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing;
|
|
|
|
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
|
|
|
|
|
|
|
// Add some data, we will use printing features
|
|
|
|
$helper->log('Add some data');
|
|
|
|
for ($i = 1; $i < 200; ++$i) {
|
|
|
|
$spreadsheet->getActiveSheet()->setCellValue('A' . $i, $i);
|
|
|
|
$spreadsheet->getActiveSheet()->setCellValue('B' . $i, 'Test value');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set header and footer. When no different headers for odd/even are used, odd header is assumed.
|
|
|
|
$helper->log('Set header/footer');
|
|
|
|
$spreadsheet->getActiveSheet()
|
2018-01-28 06:59:38 +00:00
|
|
|
->getHeaderFooter()
|
|
|
|
->setOddHeader('&L&G&C&HPlease treat this document as confidential!');
|
2016-08-31 16:15:54 +00:00
|
|
|
$spreadsheet->getActiveSheet()
|
2018-01-28 06:59:38 +00:00
|
|
|
->getHeaderFooter()
|
|
|
|
->setOddFooter('&L&B' . $spreadsheet->getProperties()->getTitle() . '&RPage &P of &N');
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
// Add a drawing to the header
|
|
|
|
$helper->log('Add a drawing to the header');
|
2017-05-17 22:02:17 +00:00
|
|
|
$drawing = new HeaderFooterDrawing();
|
2016-08-31 16:15:54 +00:00
|
|
|
$drawing->setName('PhpSpreadsheet logo');
|
2017-10-01 08:48:59 +00:00
|
|
|
$drawing->setPath(__DIR__ . '/../images/PhpSpreadsheet_logo.png');
|
2016-08-31 16:15:54 +00:00
|
|
|
$drawing->setHeight(36);
|
|
|
|
$spreadsheet->getActiveSheet()
|
2018-01-28 06:59:38 +00:00
|
|
|
->getHeaderFooter()
|
|
|
|
->addImage($drawing, HeaderFooter::IMAGE_HEADER_LEFT);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
// Set page orientation and size
|
|
|
|
$helper->log('Set page orientation and size');
|
|
|
|
$spreadsheet->getActiveSheet()
|
2018-01-28 06:59:38 +00:00
|
|
|
->getPageSetup()
|
|
|
|
->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
|
2016-08-31 16:15:54 +00:00
|
|
|
$spreadsheet->getActiveSheet()
|
2018-01-28 06:59:38 +00:00
|
|
|
->getPageSetup()
|
|
|
|
->setPaperSize(PageSetup::PAPERSIZE_A4);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
// Rename worksheet
|
|
|
|
$helper->log('Rename worksheet');
|
|
|
|
$spreadsheet->getActiveSheet()->setTitle('Printing');
|
|
|
|
|
|
|
|
// Save
|
|
|
|
$helper->write($spreadsheet, __FILE__);
|