ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
30template.php
Go to the documentation of this file.
1<?php
29error_reporting(E_ALL);
30ini_set('display_errors', TRUE);
31ini_set('display_startup_errors', TRUE);
32
33define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
34
35date_default_timezone_set('Europe/London');
36
38require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php';
39
40
41
42echo date('H:i:s') , " Load from Excel5 template" , EOL;
44$objPHPExcel = $objReader->load("templates/30template.xls");
45
46
47
48
49echo 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
67foreach($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
80echo date('H:i:s') , " Write to Excel5 format" , EOL;
82$objWriter->save(str_replace('.php', '.xls', __FILE__));
83echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
84
85
86// Echo memory peak usage
87echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
88
89// Echo done
90echo date('H:i:s') , " Done writing file" , EOL;
91echo 'File has been created in ' , getcwd() , EOL;
memory_get_peak_usage(true)/1024/1024)
Definition: 30template.php:87
const EOL
Definition: 30template.php:33
$objReader
Definition: 30template.php:43
$baseRow
Definition: 30template.php:66
$data
Definition: 30template.php:50
$objWriter
Definition: 30template.php:81
$objPHPExcel
Definition: 30template.php:44
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
An exception for terminatinating execution or to throw for unit testing.
static createWriter(PHPExcel $phpExcel, $writerType='')
Create PHPExcel_Writer_IWriter.
Definition: IOFactory.php:132
static createReader($readerType='')
Create PHPExcel_Reader_IReader.
Definition: IOFactory.php:161
static PHPToExcel($dateValue=0, $adjustToTimezone=FALSE, $timezone=NULL)
Convert a date from PHP to Excel.
Definition: Date.php:185
$r
Definition: example_031.php:79