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\MemoryDrawing;
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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');
|
2017-05-17 22:02:17 +00:00
|
|
|
$drawing = new MemoryDrawing();
|
2016-08-31 16:15:54 +00:00
|
|
|
$drawing->setName('Sample image');
|
|
|
|
$drawing->setDescription('Sample image');
|
|
|
|
$drawing->setImageResource($gdImage);
|
2017-05-17 22:02:17 +00:00
|
|
|
$drawing->setRenderingFunction(MemoryDrawing::RENDERING_JPEG);
|
|
|
|
$drawing->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
|
2016-08-31 16:15:54 +00:00
|
|
|
$drawing->setHeight(36);
|
|
|
|
$drawing->setWorksheet($spreadsheet->getActiveSheet());
|
|
|
|
|
|
|
|
// Save
|
2017-01-22 08:39:23 +00:00
|
|
|
$helper->write($spreadsheet, __FILE__, ['Xlsx', 'Html']);
|