| 1 |
<?php |
| 2 |
|
| 3 |
use PhpOffice\PhpSpreadsheet\IOFactory; |
| 4 |
|
| 5 |
require __DIR__ . '/../Header.php'; |
| 6 |
|
| 7 |
$inputFileType = 'Xlsx'; |
| 8 |
$inputFileNames = __DIR__ . '/../templates/32readwrite*[0-9].xlsx'; |
| 9 |
|
| 10 |
if ((isset($argc)) && ($argc > 1)) { |
| 11 |
$inputFileNames = []; |
| 12 |
for ($i = 1; $i < $argc; ++$i) { |
| 13 |
$inputFileNames[] = __DIR__ . '/../templates/' . $argv[$i]; |
| 14 |
} |
| 15 |
} else { |
| 16 |
$inputFileNames = glob($inputFileNames); |
| 17 |
} |
| 18 |
foreach ($inputFileNames as $inputFileName) { |
| 19 |
$inputFileNameShort = basename($inputFileName); |
| 20 |
|
| 21 |
if (!file_exists($inputFileName)) { |
| 22 |
$helper->log('File ' . $inputFileNameShort . ' does not exist'); |
| 23 |
|
| 24 |
continue; |
| 25 |
} |
| 26 |
$reader = IOFactory::createReader($inputFileType); |
| 27 |
$reader->setIncludeCharts(true); |
| 28 |
$callStartTime = microtime(true); |
| 29 |
$spreadsheet = $reader->load($inputFileName); |
| 30 |
$helper->logRead($inputFileType, $inputFileName, $callStartTime); |
| 31 |
|
| 32 |
$helper->log('Iterate worksheets looking at the charts'); |
| 33 |
foreach ($spreadsheet->getWorksheetIterator() as $worksheet) { |
| 34 |
$sheetName = $worksheet->getTitle(); |
| 35 |
$helper->log('Worksheet: ' . $sheetName); |
| 36 |
|
| 37 |
$chartNames = $worksheet->getChartNames(); |
| 38 |
if (empty($chartNames)) { |
| 39 |
$helper->log(' There are no charts in this worksheet'); |
| 40 |
} else { |
| 41 |
natsort($chartNames); |
| 42 |
foreach ($chartNames as $i => $chartName) { |
| 43 |
$chart = $worksheet->getChartByName($chartName); |
| 44 |
if ($chart->getTitle() !== null) { |
| 45 |
$caption = '"' . implode(' ', $chart->getTitle()->getCaption()) . '"'; |
| 46 |
} else { |
| 47 |
$caption = 'Untitled'; |
| 48 |
} |
| 49 |
$helper->log(' ' . $chartName . ' - ' . $caption); |
| 50 |
$indentation = str_repeat(' ', strlen($chartName) + 3); |
| 51 |
$groupCount = $chart->getPlotArea()->getPlotGroupCount(); |
| 52 |
if ($groupCount == 1) { |
| 53 |
$chartType = $chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType(); |
| 54 |
$helper->log($indentation . ' ' . $chartType); |
| 55 |
} else { |
| 56 |
$chartTypes = []; |
| 57 |
for ($i = 0; $i < $groupCount; ++$i) { |
| 58 |
$chartTypes[] = $chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType(); |
| 59 |
} |
| 60 |
$chartTypes = array_unique($chartTypes); |
| 61 |
if (count($chartTypes) == 1) { |
| 62 |
$chartType = 'Multiple Plot ' . array_pop($chartTypes); |
| 63 |
$helper->log($indentation . ' ' . $chartType); |
| 64 |
} elseif (count($chartTypes) == 0) { |
| 65 |
$helper->log($indentation . ' *** Type not yet implemented'); |
| 66 |
} else { |
| 67 |
$helper->log($indentation . ' Combination Chart'); |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
$outputFileName = $helper->getFilename($inputFileName); |
| 75 |
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); |
| 76 |
$writer->setIncludeCharts(true); |
| 77 |
$callStartTime = microtime(true); |
| 78 |
$writer->save($outputFileName); |
| 79 |
$helper->logWrite($writer, $outputFileName, $callStartTime); |
| 80 |
|
| 81 |
$spreadsheet->disconnectWorksheets(); |
| 82 |
unset($spreadsheet); |
| 83 |
} |
| 84 |
|