ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
36chartreadwritePDF.php
Go to the documentation of this file.
1 <?php
2 
4 error_reporting(E_ALL);
5 ini_set('display_errors', TRUE);
6 ini_set('display_startup_errors', TRUE);
7 date_default_timezone_set('Europe/London');
8 
9 define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
10 
11 date_default_timezone_set('Europe/London');
12 
40 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../Classes/');
41 
43 include 'PHPExcel/IOFactory.php';
44 
45 
46 // Change these values to select the Rendering library that you wish to use
47 // for PDF files, and its directory location on your server
48 //$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF;
50 //$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
51 //$rendererLibrary = 'tcPDF5.9';
52 $rendererLibrary = 'mPDF5.4';
53 //$rendererLibrary = 'domPDF0.6.0beta3';
54 $rendererLibraryPath = '/php/libraries/PDF/' . $rendererLibrary;
55 
56 
60  )) {
61  die(
62  'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
63  EOL .
64  'at the top of this script as appropriate for your directory structure'
65  );
66 }
67 
68 
69 // Change these values to select the Rendering library that you wish to use
70 // for Chart images, and its directory location on your server
72 $rendererLibrary = 'jpgraph3.5.0b1/src';
73 $rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary;
74 
75 
79  )) {
80  die(
81  'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
82  EOL .
83  'at the top of this script as appropriate for your directory structure'
84  );
85 }
86 
87 
88 $inputFileType = 'Excel2007';
89 $inputFileNames = 'templates/36write*.xlsx';
90 
91 if ((isset($argc)) && ($argc > 1)) {
93  for($i = 1; $i < $argc; ++$i) {
94  $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i];
95  }
96 } else {
98 }
100  $inputFileNameShort = basename($inputFileName);
101 
102  if (!file_exists($inputFileName)) {
103  echo date('H:i:s') , " File " , $inputFileNameShort , ' does not exist' , EOL;
104  continue;
105  }
106 
107  echo date('H:i:s') , " Load Test from $inputFileType file " , $inputFileNameShort , EOL;
108 
110  $objReader->setIncludeCharts(TRUE);
111  $objPHPExcel = $objReader->load($inputFileName);
112 
113 
114  echo date('H:i:s') , " Iterate worksheets looking at the charts" , EOL;
115  foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
116  $sheetName = $worksheet->getTitle();
117  echo 'Worksheet: ' , $sheetName , EOL;
118 
119  $chartNames = $worksheet->getChartNames();
120  if(empty($chartNames)) {
121  echo ' There are no charts in this worksheet' , EOL;
122  } else {
123  natsort($chartNames);
124  foreach($chartNames as $i => $chartName) {
125  $chart = $worksheet->getChartByName($chartName);
126  if (!is_null($chart->getTitle())) {
127  $caption = '"' . implode(' ',$chart->getTitle()->getCaption()) . '"';
128  } else {
129  $caption = 'Untitled';
130  }
131  echo ' ' , $chartName , ' - ' , $caption , EOL;
132  echo str_repeat(' ',strlen($chartName)+3);
133  $groupCount = $chart->getPlotArea()->getPlotGroupCount();
134  if ($groupCount == 1) {
135  $chartType = $chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType();
136  echo ' ' , $chartType , EOL;
137  } else {
138  $chartTypes = array();
139  for($i = 0; $i < $groupCount; ++$i) {
140  $chartTypes[] = $chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
141  }
142  $chartTypes = array_unique($chartTypes);
143  if (count($chartTypes) == 1) {
144  $chartType = 'Multiple Plot ' . array_pop($chartTypes);
145  echo ' ' , $chartType , EOL;
146  } elseif (count($chartTypes) == 0) {
147  echo ' *** Type not yet implemented' , EOL;
148  } else {
149  echo ' Combination Chart' , EOL;
150  }
151  }
152  }
153  }
154  }
155 
156 
157  $outputFileName = str_replace('.xlsx', '.pdf', basename($inputFileName));
158 
159  echo date('H:i:s') , " Write Tests to HTML file " , EOL;
161  $objWriter->setIncludeCharts(TRUE);
162  $objWriter->save($outputFileName);
163  echo date('H:i:s') , " File written to " , $outputFileName , EOL;
164 
165  $objPHPExcel->disconnectWorksheets();
166  unset($objPHPExcel);
167 }
168 
169 // Echo memory peak usage
170 echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
171 
172 // Echo done
173 echo date('H:i:s') , " Done writing files" , EOL;
174 echo 'Files have been created in ' , getcwd() , EOL;
$worksheet
static setPdfRenderer($libraryName, $libraryBaseDir)
Set details of the external library that PHPExcel should use for rendering PDF files.
Definition: Settings.php:287
$objPHPExcel
$objWriter
$argv
$rendererLibrary
static createReader($readerType='')
Create PHPExcel_Reader_IReader.
Definition: IOFactory.php:161
static setChartRenderer($libraryName, $libraryBaseDir)
Set details of the external library that PHPExcel should use for rendering charts.
Definition: Settings.php:206
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())
$rendererLibraryPath
const EOL
const PDF_RENDERER_MPDF
Definition: Settings.php:51
if(!PHPExcel_Settings::setChartRenderer($rendererName, $rendererLibraryPath)) $inputFileType
Create styles array
The data for the language used.
$rendererName
PHPExcel_IOFactory.
const CHART_RENDERER_JPGRAPH
Optional Chart Rendering libraries.
Definition: Settings.php:46
$objReader
Definition: 16csv.php:62