|
| 1 | +<?php |
| 2 | +use PhpOffice\PhpWord\Element\Chart; |
| 3 | +use PhpOffice\PhpWord\Shared\Converter; |
| 4 | + |
| 5 | +include_once 'Sample_Header.php'; |
| 6 | + |
| 7 | +// Template processor instance creation |
| 8 | +echo date('H:i:s'), ' Creating new TemplateProcessor instance...', EOL; |
| 9 | +$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_41_TemplateSetChart.docx'); |
| 10 | + |
| 11 | +$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column'); |
| 12 | +$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column'); |
| 13 | +$threeSeries = array('bar', 'line'); |
| 14 | + |
| 15 | +$categories = array('A', 'B', 'C', 'D', 'E'); |
| 16 | +$series1 = array(1, 3, 2, 5, 4); |
| 17 | +$series2 = array(3, 1, 7, 2, 6); |
| 18 | +$series3 = array(8, 3, 2, 5, 4); |
| 19 | + |
| 20 | +$i = 0; |
| 21 | +foreach ($chartTypes as $chartType) { |
| 22 | + $chart = new Chart($chartType, $categories, $series1); |
| 23 | + |
| 24 | + if (in_array($chartType, $twoSeries)) { |
| 25 | + $chart->addSeries($categories, $series2); |
| 26 | + } |
| 27 | + if (in_array($chartType, $threeSeries)) { |
| 28 | + $chart->addSeries($categories, $series3); |
| 29 | + } |
| 30 | + |
| 31 | + $chart->getStyle() |
| 32 | + ->setWidth(Converter::inchToEmu(3)) |
| 33 | + ->setHeight(Converter::inchToEmu(3)); |
| 34 | + |
| 35 | + $templateProcessor->setChart("chart{$i}", $chart); |
| 36 | + $i++; |
| 37 | +} |
| 38 | + |
| 39 | +echo date('H:i:s'), ' Saving the result document...', EOL; |
| 40 | +$templateProcessor->saveAs('results/Sample_41_TemplateSetChart.docx'); |
| 41 | + |
| 42 | +echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_41_TemplateSetChart.docx'); |
| 43 | +if (!CLI) { |
| 44 | + include_once 'Sample_Footer.php'; |
| 45 | +} |
0 commit comments