| 1 |
<?php |
| 2 |
|
| 3 |
/** Error reporting */ |
| 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 |
|
| 13 |
/** |
| 14 |
* PHPExcel |
| 15 |
* |
| 16 |
* Copyright (C) 2006 - 2014 PHPExcel |
| 17 |
* |
| 18 |
* This library is free software; you can redistribute it and/or |
| 19 |
* modify it under the terms of the GNU Lesser General Public |
| 20 |
* License as published by the Free Software Foundation; either |
| 21 |
* version 2.1 of the License, or (at your option) any later version. |
| 22 |
* |
| 23 |
* This library is distributed in the hope that it will be useful, |
| 24 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 26 |
* Lesser General Public License for more details. |
| 27 |
* |
| 28 |
* You should have received a copy of the GNU Lesser General Public |
| 29 |
* License along with this library; if not, write to the Free Software |
| 30 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 31 |
* |
| 32 |
* @category PHPExcel |
| 33 |
* @package PHPExcel |
| 34 |
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) |
| 35 |
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
| 36 |
* @version ##VERSION##, ##DATE## |
| 37 |
*/ |
| 38 |
|
| 39 |
/** Include path **/ |
| 40 |
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../Classes/'); |
| 41 |
|
| 42 |
/** PHPExcel_IOFactory */ |
| 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 |
| 48 |
$rendererName = PHPExcel_Settings::CHART_RENDERER_JPGRAPH; |
| 49 |
$rendererLibrary = 'jpgraph3.5.0b1/src'; |
| 50 |
$rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary; |
| 51 |
|
| 52 |
|
| 53 |
if (!PHPExcel_Settings::setChartRenderer( |
| 54 |
$rendererName, |
| 55 |
$rendererLibraryPath |
| 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)) { |
| 69 |
$inputFileNames = array(); |
| 70 |
for($i = 1; $i < $argc; ++$i) { |
| 71 |
$inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i]; |
| 72 |
} |
| 73 |
} else { |
| 74 |
$inputFileNames = glob($inputFileNames); |
| 75 |
} |
| 76 |
foreach($inputFileNames as $inputFileName) { |
| 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 |
|
| 86 |
$objReader = PHPExcel_IOFactory::createReader($inputFileType); |
| 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; |
| 137 |
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML'); |
| 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; |
| 152 |
|