ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
30template.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/IOFactory.php';
39 
40 
41 
42 echo date('H:i:s') , " Load from Excel5 template" , EOL;
44 $objPHPExcel = $objReader->load("templates/30template.xls");
45 
46 
47 
48 
49 echo date('H:i:s') , " Add new data to the template" , EOL;
50 $data = array(array('title' => 'Excel for dummies',
51  'price' => 17.99,
52  'quantity' => 2
53  ),
54  array('title' => 'PHP for dummies',
55  'price' => 15.99,
56  'quantity' => 1
57  ),
58  array('title' => 'Inside OOP',
59  'price' => 12.95,
60  'quantity' => 1
61  )
62  );
63 
64 $objPHPExcel->getActiveSheet()->setCellValue('D1', PHPExcel_Shared_Date::PHPToExcel(time()));
65 
67 foreach($data as $r => $dataRow) {
68  $row = $baseRow + $r;
69  $objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1);
70 
71  $objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $r+1)
72  ->setCellValue('B'.$row, $dataRow['title'])
73  ->setCellValue('C'.$row, $dataRow['price'])
74  ->setCellValue('D'.$row, $dataRow['quantity'])
75  ->setCellValue('E'.$row, '=C'.$row.'*D'.$row);
76 }
77 $objPHPExcel->getActiveSheet()->removeRow($baseRow-1,1);
78 
79 
80 echo date('H:i:s') , " Write to Excel5 format" , EOL;
82 $objWriter->save(str_replace('.php', '.xls', __FILE__));
83 echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
84 
85 
86 // Echo memory peak usage
87 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
88 
89 // Echo done
90 echo date('H:i:s') , " Done writing file" , EOL;
91 echo 'File has been created in ' , getcwd() , EOL;
$data
Definition: 30template.php:50
$objWriter
Definition: 30template.php:81
$baseRow
Definition: 30template.php:66
const EOL
Definition: 30template.php:33
$r
Definition: example_031.php:79
static createReader($readerType='')
Create PHPExcel_Reader_IReader.
Definition: IOFactory.php:161
static createWriter(PHPExcel $phpExcel, $writerType='')
Create PHPExcel_Writer_IWriter.
Definition: IOFactory.php:132
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())
$objReader
Definition: 30template.php:43
$objPHPExcel
Definition: 30template.php:44
Create styles array
The data for the language used.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static PHPToExcel($dateValue=0, $adjustToTimezone=FALSE, $timezone=NULL)
Convert a date from PHP to Excel.
Definition: Date.php:185