2016-08-31 16:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require __DIR__ . '/Header.php';
|
|
|
|
|
|
|
|
// Create new Spreadsheet object
|
|
|
|
$helper->log('Create new Spreadsheet object');
|
2016-08-31 17:18:12 +00:00
|
|
|
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
// Set document properties
|
|
|
|
$helper->log('Set document properties');
|
|
|
|
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
|
|
|
|
->setLastModifiedBy('Maarten Balliauw')
|
|
|
|
->setTitle('PhpSpreadsheet Test Document')
|
|
|
|
->setSubject('PhpSpreadsheet Test Document')
|
|
|
|
->setDescription('Test document for PhpSpreadsheet, generated using PHP classes.')
|
|
|
|
->setKeywords('office PhpSpreadsheet php')
|
|
|
|
->setCategory('Test result file');
|
|
|
|
|
|
|
|
// Add some data
|
|
|
|
$helper->log('Add some data');
|
|
|
|
$spreadsheet->setActiveSheetIndex(0)
|
|
|
|
->setCellValue('A1', 'Hello')
|
|
|
|
->setCellValue('B2', 'world!')
|
|
|
|
->setCellValue('C1', 'Hello')
|
|
|
|
->setCellValue('D2', 'world!');
|
|
|
|
|
|
|
|
// Miscellaneous glyphs, UTF-8
|
|
|
|
$spreadsheet->setActiveSheetIndex(0)
|
|
|
|
->setCellValue('A4', 'Miscellaneous glyphs')
|
|
|
|
->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
|
|
|
|
|
|
|
|
$spreadsheet->getActiveSheet()->setCellValue('A8', "Hello\nWorld");
|
|
|
|
$spreadsheet->getActiveSheet()->getRowDimension(8)->setRowHeight(-1);
|
|
|
|
$spreadsheet->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true);
|
|
|
|
|
|
|
|
// Rename worksheet
|
|
|
|
$helper->log('Rename worksheet');
|
|
|
|
$spreadsheet->getActiveSheet()->setTitle('Simple');
|
|
|
|
|
|
|
|
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
|
|
|
$spreadsheet->setActiveSheetIndex(0);
|
|
|
|
|
|
|
|
// Save Excel 2007 file
|
|
|
|
$helper->log('Write to Excel2007 format');
|
|
|
|
|
|
|
|
// Use PCLZip rather than ZipArchive to create the Excel2007 OfficeOpenXML file
|
2016-08-31 17:18:12 +00:00
|
|
|
\PhpOffice\PhpSpreadsheet\Settings::setZipClass(\PhpOffice\PhpSpreadsheet\Settings::PCLZIP);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
// Save
|
|
|
|
$helper->write($spreadsheet, __FILE__, ['Excel2007' => 'xlsx']);
|