ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
25inmemoryimage.php
Go to the documentation of this file.
1 <?php
29 error_reporting(E_ALL);
30 ini_set('display_errors', TRUE);
31 ini_set('display_startup_errors', TRUE);
32 
33 define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
34 
35 date_default_timezone_set('Europe/London');
36 
38 require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
39 
40 
41 // Create new PHPExcel object
42 echo date('H:i:s') , " Create new PHPExcel object" , EOL;
44 
45 // Set document properties
46 echo date('H:i:s') , " Set document properties" , EOL;
47 $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
48  ->setLastModifiedBy("Maarten Balliauw")
49  ->setTitle("Office 2007 XLSX Test Document")
50  ->setSubject("Office 2007 XLSX Test Document")
51  ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
52  ->setKeywords("office 2007 openxml php")
53  ->setCategory("Test result file");
54 
55 // Generate an image
56 echo date('H:i:s') , " Generate an image" , EOL;
57 $gdImage = @imagecreatetruecolor(120, 20) or die('Cannot Initialize new GD image stream');
58 $textColor = imagecolorallocate($gdImage, 255, 255, 255);
59 imagestring($gdImage, 1, 5, 5, 'Created with PHPExcel', $textColor);
60 
61 // Add a drawing to the worksheet
62 echo date('H:i:s') , " Add a drawing to the worksheet" , EOL;
64 $objDrawing->setName('Sample image');
65 $objDrawing->setDescription('Sample image');
66 $objDrawing->setImageResource($gdImage);
67 $objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
68 $objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
69 $objDrawing->setHeight(36);
70 $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
71 
72 echo date('H:i:s') , " Write to Excel2007 format" , EOL;
73 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
74 $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
75 echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
76 
77 
78 // Echo memory peak usage
79 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
80 
81 // Echo done
82 echo date('H:i:s') , " Done writing file" , EOL;
83 echo 'File has been created in ' , getcwd() , EOL;
$textColor
$objDrawing
$objPHPExcel
File written to
Peak memory usage
Add a drawing to the worksheet
Generate an image
if($is_dev) echo "Review changes write something in WHATSNEW and and then commit with log PHP_EOL
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
Done writing file
Peak memory memory_get_peak_usage(true)/1024/1024) MB
const EOL
$gdImage
Add data(end) s
Write to Excel2007 format
$objWriter