38 lines
1.5 KiB
PHP
38 lines
1.5 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');
|
||
|
|
||
|
// Generate an image
|
||
|
$helper->log('Generate an image');
|
||
|
$gdImage = @imagecreatetruecolor(120, 20) or die('Cannot Initialize new GD image stream');
|
||
|
$textColor = imagecolorallocate($gdImage, 255, 255, 255);
|
||
|
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
|
||
|
|
||
|
// Add a drawing to the worksheet
|
||
|
$helper->log('Add a drawing to the worksheet');
|
||
|
$drawing = new \PhpSpreadsheet\Worksheet\MemoryDrawing();
|
||
|
$drawing->setName('Sample image');
|
||
|
$drawing->setDescription('Sample image');
|
||
|
$drawing->setImageResource($gdImage);
|
||
|
$drawing->setRenderingFunction(\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG);
|
||
|
$drawing->setMimeType(\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT);
|
||
|
$drawing->setHeight(36);
|
||
|
$drawing->setWorksheet($spreadsheet->getActiveSheet());
|
||
|
|
||
|
// Save
|
||
|
$helper->write($spreadsheet, __FILE__, ['Excel2007' => 'xlsx', 'HTML' => 'html']);
|