Skip to content

Commit 1168789

Browse files
author
Antoine de Troostembergh
committed
fix formatting
1 parent 214df1a commit 1168789

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

docs/templates-processing.rst

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,28 @@ See ``Sample_40_TemplateSetComplexValue.php`` for examples.
249249
$table->addCell(150)->addText('Cell B2');
250250
$table->addCell(150)->addText('Cell B3');
251251
$templateProcessor->setComplexBlock('table', $table);
252-
252+
253+
setChartValue
254+
"""""""""""""
255+
Replace a variable by a chart.
256+
257+
.. code-block:: php
258+
259+
$categories = array('A', 'B', 'C', 'D', 'E');
260+
$series1 = array(1, 3, 2, 5, 4);
261+
$chart = new Chart('doughnut', $categories, $series1);
262+
$templateProcessor->setChartValue('myChart', $chart);
263+
253264
save
254-
"""""""""
265+
""""
255266
Saves the loaded template within the current directory. Returns the file path.
256267

257268
.. code-block:: php
258269
259270
$filepath = $templateProcessor->save();
260271
261272
saveAs
262-
"""""""""
273+
""""""
263274
Saves a copy of the loaded template in the indicated path.
264275

265276
.. code-block:: php

samples/Sample_41_TemplateSetChart.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@
1717
$series2 = array(3, 1, 7, 2, 6);
1818
$series3 = array(8, 3, 2, 5, 4);
1919

20-
$i=0;
20+
$i = 0;
2121
foreach ($chartTypes as $chartType) {
22-
$chart = new Chart($chartType, $categories, $series1);
22+
$chart = new Chart($chartType, $categories, $series1);
2323

24-
if (in_array($chartType, $twoSeries)) {
25-
$chart->addSeries($categories, $series2);
26-
}
27-
if (in_array($chartType, $threeSeries)) {
28-
$chart->addSeries($categories, $series3);
29-
}
24+
if (in_array($chartType, $twoSeries)) {
25+
$chart->addSeries($categories, $series2);
26+
}
27+
if (in_array($chartType, $threeSeries)) {
28+
$chart->addSeries($categories, $series3);
29+
}
3030

31-
$chart->getStyle()
32-
->setWidth(Converter::inchToEmu(3))
33-
->setHeight(Converter::inchToEmu(3));
31+
$chart->getStyle()
32+
->setWidth(Converter::inchToEmu(3))
33+
->setHeight(Converter::inchToEmu(3));
3434

35-
$templateProcessor->setChart("chart{$i}", $chart);
36-
$i++;
35+
$templateProcessor->setChart("chart{$i}", $chart);
36+
$i++;
3737
}
3838

3939
echo date('H:i:s'), ' Saving the result document...', EOL;

src/PhpWord/TemplateProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,12 @@ public function setChart($search, \PhpOffice\PhpWord\Element\AbstractElement $ch
365365
$objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $elementName;
366366

367367
// Get the next relation id
368-
$rId= $this->getNextRelationsIndex($this->getMainPartName());
368+
$rId = $this->getNextRelationsIndex($this->getMainPartName());
369369
$chart->setRelationId($rId);
370370

371371
// Define the chart filename
372372
$filename = "charts/chart{$rId}.xml";
373-
373+
374374
// Get the part writer
375375
$writerPart = new \PhpOffice\PhpWord\Writer\Word2007\Part\Chart();
376376
$writerPart->setElement($chart);

src/PhpWord/Writer/Word2007/Part/Chart.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false)
267267
$this->writeSeriesItem($xmlWriter, 'val', $values);
268268

269269
// check that there are colors
270-
if (is_array($colors) && count($colors)>0) {
270+
if (is_array($colors) && count($colors) > 0) {
271271
// assign a color to each value
272-
$valueIndex=0;
273-
foreach ($values as $value) {
272+
$valueIndex = 0;
273+
for ($i = 1; $i < count($values); $i++) {
274274
// check that there are still enought colors
275275
$xmlWriter->startElement('c:dPt');
276276
$xmlWriter->writeElementBlock('c:idx', 'val', $valueIndex);

tests/PhpWord/TemplateProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public function testSetImageValue()
401401
return $imagePath;
402402
},
403403
'documentContent' => array('path' => $imagePath, 'width' => 500, 'height' => 500),
404-
'footerValue' => array('path' => $imagePath, 'width' => 100, 'height' => 50, 'ratio' => false),
404+
'footerValue' => array('path' => $imagePath, 'width' => 100, 'height' => 50, 'ratio' => false),
405405
);
406406
$templateProcessor->setImageValue(array_keys($variablesReplace), $variablesReplace);
407407

0 commit comments

Comments
 (0)