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
|
|
|
|
2017-10-21 16:54:14 +00:00
|
|
|
IOFactory::registerWriter('Pdf', \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf::class);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
2018-08-06 02:02:16 +00:00
|
|
|
// Change these values to select the Rendering library that you wish to use
|
2017-10-28 16:58:42 +00:00
|
|
|
Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph::class);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
2016-10-06 11:39:10 +00:00
|
|
|
$inputFileType = 'Xlsx';
|
2017-10-01 08:48:59 +00:00
|
|
|
$inputFileNames = __DIR__ . '/../templates/36write*.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)) {
|
|
|
|
$helper->log('File ' . $inputFileNameShort . ' does not exist');
|
2017-10-01 11:07:04 +00:00
|
|
|
|
2016-08-31 16:15:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$helper->log("Load Test from $inputFileType file " . $inputFileNameShort);
|
|
|
|
|
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)) {
|
2017-10-01 08:48:59 +00:00
|
|
|
$helper->log(' There are no charts in this worksheet');
|
2016-08-31 16:15:54 +00:00
|
|
|
} 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);
|
|
|
|
$helper->log(str_repeat(' ', strlen($chartName) + 3));
|
2016-08-31 16:15:54 +00:00
|
|
|
$groupCount = $chart->getPlotArea()->getPlotGroupCount();
|
|
|
|
if ($groupCount == 1) {
|
|
|
|
$chartType = $chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType();
|
2017-10-01 08:48:59 +00:00
|
|
|
$helper->log(' ' . $chartType);
|
2016-08-31 16:15:54 +00:00
|
|
|
} else {
|
|
|
|
$chartTypes = [];
|
|
|
|
for ($i = 0; $i < $groupCount; ++$i) {
|
|
|
|
$chartTypes[] = $chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
|
|
|
|
}
|
|
|
|
$chartTypes = array_unique($chartTypes);
|
|
|
|
if (count($chartTypes) == 1) {
|
|
|
|
$chartType = 'Multiple Plot ' . array_pop($chartTypes);
|
2017-10-01 08:48:59 +00:00
|
|
|
$helper->log(' ' . $chartType);
|
2016-08-31 16:15:54 +00:00
|
|
|
} elseif (count($chartTypes) == 0) {
|
2017-10-01 08:48:59 +00:00
|
|
|
$helper->log(' *** Type not yet implemented');
|
2016-08-31 16:15:54 +00:00
|
|
|
} else {
|
2017-10-01 08:48:59 +00:00
|
|
|
$helper->log(' Combination Chart');
|
2016-08-31 16:15:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save
|
2017-10-28 16:58:42 +00:00
|
|
|
$filename = $helper->getFilename($inputFileName, 'pdf');
|
2017-05-17 22:02:17 +00:00
|
|
|
$writer = IOFactory::createWriter($spreadsheet, 'Pdf');
|
2016-08-31 16:15:54 +00:00
|
|
|
$writer->setIncludeCharts(true);
|
|
|
|
$callStartTime = microtime(true);
|
|
|
|
$writer->save($filename);
|
|
|
|
$helper->logWrite($writer, $filename, $callStartTime);
|
|
|
|
|
|
|
|
$spreadsheet->disconnectWorksheets();
|
|
|
|
unset($spreadsheet);
|
|
|
|
}
|