2016-08-31 16:15:54 +00:00
< ? php
2017-05-17 22:02:17 +00:00
use PhpOffice\PhpSpreadsheet\IOFactory ;
use PhpOffice\PhpSpreadsheet\Settings ;
2017-10-01 08:48:59 +00:00
require __DIR__ . '/../Header.php' ;
2016-08-31 16:15:54 +00:00
// Change these values to select the Rendering library that you wish to use
// and its directory location on your server
2017-05-17 22:02:17 +00:00
$rendererName = Settings :: CHART_RENDERER_JPGRAPH ;
2016-08-31 16:15:54 +00:00
$rendererLibrary = 'jpgraph3.5.0b1/src/' ;
$rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary ;
2017-05-17 22:02:17 +00:00
if ( ! Settings :: setChartRenderer ( $rendererName , $rendererLibraryPath )) {
2016-08-31 16:15:54 +00:00
$helper -> log ( 'NOTICE: Please set the $rendererName and $rendererLibraryPath values at the top of this script as appropriate for your directory structure' );
return ;
}
2016-10-06 11:39:10 +00:00
$inputFileType = 'Xlsx' ;
2017-10-01 08:48:59 +00:00
$inputFileNames = __DIR__ . '/../templates/32readwrite*[0-9].xlsx' ;
2016-08-31 16:15:54 +00:00
if (( isset ( $argc )) && ( $argc > 1 )) {
$inputFileNames = [];
for ( $i = 1 ; $i < $argc ; ++ $i ) {
2017-10-01 08:48:59 +00:00
$inputFileNames [] = __DIR__ . '/../templates/' . $argv [ $i ];
2016-08-31 16:15:54 +00:00
}
} else {
$inputFileNames = glob ( $inputFileNames );
}
foreach ( $inputFileNames as $inputFileName ) {
$inputFileNameShort = basename ( $inputFileName );
if ( ! file_exists ( $inputFileName )) {
2017-10-01 08:48:59 +00:00
$helper -> log ( 'File ' . $inputFileNameShort . ' does not exist' );
2017-10-01 11:07:04 +00:00
2016-08-31 16:15:54 +00:00
continue ;
}
2017-10-01 08:48:59 +00:00
$helper -> log ( " Load Test from $inputFileType file " . $inputFileNameShort );
2016-08-31 16:15:54 +00:00
2017-05-17 22:02:17 +00:00
$reader = IOFactory :: createReader ( $inputFileType );
2016-08-31 16:15:54 +00:00
$reader -> setIncludeCharts ( true );
$spreadsheet = $reader -> load ( $inputFileName );
$helper -> log ( 'Iterate worksheets looking at the charts' );
foreach ( $spreadsheet -> getWorksheetIterator () as $worksheet ) {
$sheetName = $worksheet -> getTitle ();
2017-10-01 08:48:59 +00:00
$helper -> log ( 'Worksheet: ' . $sheetName );
2016-08-31 16:15:54 +00:00
$chartNames = $worksheet -> getChartNames ();
if ( empty ( $chartNames )) {
$helper -> log ( ' There are no charts in this worksheet' );
} else {
natsort ( $chartNames );
foreach ( $chartNames as $i => $chartName ) {
$chart = $worksheet -> getChartByName ( $chartName );
2017-10-01 11:07:04 +00:00
if ( $chart -> getTitle () !== null ) {
2016-08-31 16:15:54 +00:00
$caption = '"' . implode ( ' ' , $chart -> getTitle () -> getCaption ()) . '"' ;
} else {
$caption = 'Untitled' ;
}
2017-10-01 08:48:59 +00:00
$helper -> log ( ' ' . $chartName . ' - ' . $caption );
2016-08-31 16:15:54 +00:00
$jpegFile = $helper -> getFilename ( '35-' . $inputFileNameShort , 'jpg' );
if ( file_exists ( $jpegFile )) {
unlink ( $jpegFile );
}
2017-10-01 11:07:04 +00:00
2016-08-31 16:15:54 +00:00
try {
$chart -> render ( $jpegFile );
} catch ( Exception $e ) {
2017-10-01 08:48:59 +00:00
$helper -> log ( 'Error rendering chart: ' . $e -> getMessage ());
2016-08-31 16:15:54 +00:00
}
}
}
}
$spreadsheet -> disconnectWorksheets ();
unset ( $spreadsheet );
}
$helper -> log ( 'Done rendering charts as images' );