PhpSpreadsheet/samples/22_Heavily_formatted.php
Adrien Crivelli 2922a13764
Reorganize code samples
This introduce a helper class that should be used to log things,
avoiding a lot of boilerplate code.

Also all output are made in /tmp folder instead of beside the script
itself. This is because there is a high chance that the folder containing
the script is not writtable by webserver. So using the /tmp folder
makes it more likely to works in a variety of setup.
2016-09-01 01:17:13 +09:00

45 lines
1.4 KiB
PHP

<?php
require __DIR__ . '/Header.php';
// Create new Spreadsheet object
$helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpSpreadsheet\Spreadsheet();
// Set document properties
$helper->log('Set document properties');
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
->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');
// Add some data
$helper->log('Add some data');
$spreadsheet->setActiveSheetIndex(0);
$spreadsheet->getActiveSheet()->getStyle('A1:T100')->applyFromArray(
['fill' => [
'type' => \PhpSpreadsheet\Style\Fill::FILL_SOLID,
'color' => ['argb' => 'FFCCFFCC'],
],
'borders' => [
'bottom' => ['style' => \PhpSpreadsheet\Style\Border::BORDER_THIN],
'right' => ['style' => \PhpSpreadsheet\Style\Border::BORDER_MEDIUM],
],
]
);
$spreadsheet->getActiveSheet()->getStyle('C5:R95')->applyFromArray(
['fill' => [
'type' => \PhpSpreadsheet\Style\Fill::FILL_SOLID,
'color' => ['argb' => 'FFFFFF00'],
],
]
);
// Save
$helper->write($spreadsheet, __FILE__);