ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
36chartreadwriteHTML.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 // and its directory location on your server
49 $rendererLibrary = 'jpgraph3.5.0b1/src';
50 $rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary;
51 
52 
56  )) {
57  die(
58  'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
59  EOL .
60  'at the top of this script as appropriate for your directory structure'
61  );
62 }
63 
64 
65 $inputFileType = 'Excel2007';
66 $inputFileNames = 'templates/36write*.xlsx';
67 
68 if ((isset($argc)) && ($argc > 1)) {
70  for($i = 1; $i < $argc; ++$i) {
71  $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i];
72  }
73 } else {
75 }
77  $inputFileNameShort = basename($inputFileName);
78 
79  if (!file_exists($inputFileName)) {
80  echo date('H:i:s') , " File " , $inputFileNameShort , ' does not exist' , EOL;
81  continue;
82  }
83 
84  echo date('H:i:s') , " Load Test from $inputFileType file " , $inputFileNameShort , EOL;
85 
87  $objReader->setIncludeCharts(TRUE);
88  $objPHPExcel = $objReader->load($inputFileName);
89 
90 
91  echo date('H:i:s') , " Iterate worksheets looking at the charts" , EOL;
92  foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
93  $sheetName = $worksheet->getTitle();
94  echo 'Worksheet: ' , $sheetName , EOL;
95 
96  $chartNames = $worksheet->getChartNames();
97  if(empty($chartNames)) {
98  echo ' There are no charts in this worksheet' , EOL;
99  } else {
100  natsort($chartNames);
101  foreach($chartNames as $i => $chartName) {
102  $chart = $worksheet->getChartByName($chartName);
103  if (!is_null($chart->getTitle())) {
104  $caption = '"' . implode(' ',$chart->getTitle()->getCaption()) . '"';
105  } else {
106  $caption = 'Untitled';
107  }
108  echo ' ' , $chartName , ' - ' , $caption , EOL;
109  echo str_repeat(' ',strlen($chartName)+3);
110  $groupCount = $chart->getPlotArea()->getPlotGroupCount();
111  if ($groupCount == 1) {
112  $chartType = $chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType();
113  echo ' ' , $chartType , EOL;
114  } else {
115  $chartTypes = array();
116  for($i = 0; $i < $groupCount; ++$i) {
117  $chartTypes[] = $chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
118  }
119  $chartTypes = array_unique($chartTypes);
120  if (count($chartTypes) == 1) {
121  $chartType = 'Multiple Plot ' . array_pop($chartTypes);
122  echo ' ' , $chartType , EOL;
123  } elseif (count($chartTypes) == 0) {
124  echo ' *** Type not yet implemented' , EOL;
125  } else {
126  echo ' Combination Chart' , EOL;
127  }
128  }
129  }
130  }
131  }
132 
133 
134  $outputFileName = str_replace('.xlsx', '.html', basename($inputFileName));
135 
136  echo date('H:i:s') , " Write Tests to HTML file " , EOL;
138  $objWriter->setIncludeCharts(TRUE);
139  $objWriter->save($outputFileName);
140  echo date('H:i:s') , " File written to " , $outputFileName , EOL;
141 
142  $objPHPExcel->disconnectWorksheets();
143  unset($objPHPExcel);
144 }
145 
146 // Echo memory peak usage
147 echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
148 
149 // Echo done
150 echo date('H:i:s') , " Done writing files" , EOL;
151 echo 'Files have been created in ' , getcwd() , EOL;
$worksheet
global $argv
Definition: svg-scanner.php:41
$objPHPExcel
$rendererName
PHPExcel_IOFactory.
$objWriter
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())
if(!PHPExcel_Settings::setChartRenderer($rendererName, $rendererLibraryPath)) $inputFileType
Create styles array
The data for the language used.
const EOL
$i
Definition: disco.tpl.php:19
const CHART_RENDERER_JPGRAPH
Optional Chart Rendering libraries.
Definition: Settings.php:46
$rendererLibraryPath
$objReader
Definition: 16csv.php:62