ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
16csv.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 date_default_timezone_set('Europe/London');
33 
34 define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
35 
36 date_default_timezone_set('Europe/London');
37 
38 include "05featuredemo.inc.php";
39 
41 require_once '../Classes/PHPExcel/IOFactory.php';
42 
43 
44 echo date('H:i:s') , " Write to CSV format" , EOL;
45 $callStartTime = microtime(true);
46 
48  ->setEnclosure('"')
49  ->setLineEnding("\r\n")
50  ->setSheetIndex(0)
51  ->save(str_replace('.php', '.csv', __FILE__));
52 $callEndTime = microtime(true);
54 echo date('H:i:s') , " File written to " , str_replace('.php', '.csv', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
55 echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
56 // Echo memory usage
57 echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
58 
59 
60 echo date('H:i:s') , " Read from CSV format" , EOL;
61 $callStartTime = microtime(true);
62 $objReader = PHPExcel_IOFactory::createReader('CSV')->setDelimiter(',')
63  ->setEnclosure('"')
64  ->setLineEnding("\r\n")
65  ->setSheetIndex(0);
66 $objPHPExcelFromCSV = $objReader->load(str_replace('.php', '.csv', __FILE__));
67 
68 $callEndTime = microtime(true);
70 echo 'Call time to reload Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
71 // Echo memory usage
72 echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
73 
74 
75 echo date('H:i:s') , " Write to Excel2007 format" , EOL;
76 $callStartTime = microtime(true);
77 
79 $objWriter2007->save(str_replace('.php', '.xlsx', __FILE__));
80 $callEndTime = microtime(true);
82 echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
83 echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
84 // Echo memory usage
85 echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
86 
87 
88 echo date('H:i:s') , " Write to CSV format" , EOL;
89 $callStartTime = microtime(true);
90 
92 $objWriterCSV->setExcelCompatibility(true);
93 $objWriterCSV->save(str_replace('.php', '_excel.csv', __FILE__));
94 $callEndTime = microtime(true);
96 echo date('H:i:s') , " File written to " , str_replace('.php', '_excel.csv', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
97 echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
98 // Echo memory usage
99 echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
100 
101 
102 // Echo memory peak usage
103 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
104 
105 // Echo done
106 echo date('H:i:s') , " Done writing files" , EOL;
107 echo 'Files have been created in ' , getcwd() , EOL;
const EOL
Definition: 16csv.php:34
$objPHPExcel
$objWriter
Definition: 16csv.php:47
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
$callTime
Definition: 16csv.php:53
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$callStartTime
Definition: 16csv.php:45
$callEndTime
Definition: 16csv.php:52
$objWriterCSV
Definition: 16csv.php:91
$objPHPExcelFromCSV
Definition: 16csv.php:66
$objReader
Definition: 16csv.php:62
$objWriter2007
Definition: 16csv.php:78