ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
26utf8.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.php';
39
40
41// Change these values to select the PDF Rendering library that you wish to use
42// and its directory location on your server
43//$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF;
44//$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
46//$rendererLibrary = 'tcPDF5.9';
47//$rendererLibrary = 'mPDF5.4';
48$rendererLibrary = 'domPDF0.6.0beta3';
49$rendererLibraryPath = '/php/libraries/PDF/' . $rendererLibrary;
50
51
52// Read from Excel2007 (.xlsx) template
53echo date('H:i:s') , " Load Excel2007 template file" , EOL;
55$objPHPExcel = $objReader->load("templates/26template.xlsx");
56
59// Export to Excel2007 (.xlsx)
60echo date('H:i:s') , " Write to Excel5 format" , EOL;
62$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
63echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
64
65// Export to Excel5 (.xls)
66echo date('H:i:s') , " Write to Excel5 format" , EOL;
68$objWriter->save(str_replace('.php', '.xls', __FILE__));
69echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
70
71// Export to HTML (.html)
72echo date('H:i:s') , " Write to HTML format" , EOL;
74$objWriter->save(str_replace('.php', '.htm', __FILE__));
75echo date('H:i:s') , " File written to " , str_replace('.php', '.htm', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
76
77// Export to PDF (.pdf)
78echo date('H:i:s') , " Write to PDF format" , EOL;
79try {
83 )) {
84 echo (
85 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
86 EOL .
87 'at the top of this script as appropriate for your directory structure' .
88 EOL
89 );
90 } else {
92 $objWriter->save(str_replace('.php', '.pdf', __FILE__));
93 echo date('H:i:s') , " File written to " , str_replace('.php', '.pdf', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
94 }
95} catch (Exception $e) {
96 echo date('H:i:s') , ' EXCEPTION: ', $e->getMessage() , EOL;
97}
98
99// Remove first two rows with field headers before exporting to CSV
100echo date('H:i:s') , " Removing first two heading rows for CSV export" , EOL;
101$objWorksheet = $objPHPExcel->getActiveSheet();
102$objWorksheet->removeRow(1, 2);
103
104// Export to CSV (.csv)
105echo date('H:i:s') , " Write to CSV format" , EOL;
107$objWriter->save(str_replace('.php', '.csv', __FILE__));
108echo date('H:i:s') , " File written to " , str_replace('.php', '.csv', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
109
110// Export to CSV with BOM (.csv)
111echo date('H:i:s') , " Write to CSV format (with BOM)" , EOL;
112$objWriter->setUseBOM(true);
113$objWriter->save(str_replace('.php', '-bom.csv', __FILE__));
114echo date('H:i:s') , " File written to " , str_replace('.php', '-bom.csv', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
115
116
117// Echo memory peak usage
118echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
119
120// Echo done
121echo date('H:i:s') , " Done writing files" , EOL;
122echo 'Files have been created in ' , getcwd() , EOL;
$rendererName
Include PHPExcel.
Definition: 26utf8.php:45
memory_get_peak_usage(true)/1024/1024)
Definition: 26utf8.php:118
const EOL
Definition: 26utf8.php:33
$objReader
Definition: 26utf8.php:54
$rendererLibrary
Definition: 26utf8.php:48
$rendererLibraryPath
Definition: 26utf8.php:49
$objWorksheet
Definition: 26utf8.php:101
$objWriter
Definition: 26utf8.php:61
$objPHPExcel
Definition: 26utf8.php:55
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
const PDF_RENDERER_DOMPDF
Definition: Settings.php:50
static setPdfRenderer($libraryName, $libraryBaseDir)
Set details of the external library that PHPExcel should use for rendering PDF files.
Definition: Settings.php:287