Skip to content

Commit d9cc4dd

Browse files
authored
Merge pull request #778 from Progi1984/pr671
PowerPoint2007 Writer : Fixed issue when first element in series is null
2 parents ce54114 + d5c46c3 commit d9cc4dd

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

docs/changes/1.1.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- PowerPoint2007 Writer : Fixed column indices for embedded spreadsheets - [@michael-roth](https://github.com/michael-roth) in [#773](https://github.com/PHPOffice/PHPPresentation/pull/773)
2525
- PowerPoint2007 Reader : Load images from file only if valid - [@aelliott1485](https://github.com/aelliott1485) in [#775](https://github.com/PHPOffice/PHPPresentation/pull/775)
2626
- PowerPoint2007 Writer : Fixed broken video file relationship - [@potofcoffee](https://github.com/potofcoffee) in [#776](https://github.com/PHPOffice/PHPPresentation/pull/776)
27+
- PowerPoint2007 Writer : Fixed issue when first element in series is null - [@ksmeeks0001](https://github.com/ksmeeks0001) in [#778](https://github.com/PHPOffice/PHPPresentation/pull/778)
2728

2829
## BC Breaks
2930
- `PhpOffice\PhpPresentation\Style\Outline` : the width is now based on pixels (before in points)

src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,16 @@ protected function writeMultipleValuesOrReference(XMLWriter $objWriter, bool $is
347347
// c:strLit / c:numLit
348348
// c:strRef / c:numRef
349349
$referenceType = ($isReference ? 'Ref' : 'Lit');
350-
$dataType = is_numeric($values[0]) ? 'num' : 'str';
350+
351+
// Get data type from first non-null value
352+
$dataType = array_reduce($values, function ($carry, $item) {
353+
if (!isset($item)) {
354+
return $carry;
355+
}
356+
357+
return is_numeric($item) ? 'num' : 'str';
358+
}, 'num');
359+
351360
$objWriter->startElement('c:' . $dataType . $referenceType);
352361

353362
$numValues = count($values);

tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,76 @@ public function testChartDisplayBlankAs(): void
9999
$this->assertIsSchemaECMA376Valid();
100100
}
101101

102+
/**
103+
* @dataProvider dataProviderIncludedSpreadsheet
104+
*/
105+
public function testChartIncludeSpreadsheetNullValue(string $chartType, string $chartElementName): void
106+
{
107+
$seriesData = array_merge(['Z' => null], $this->seriesData);
108+
109+
$oSlide = $this->oPresentation->getActiveSlide();
110+
$oShape = $oSlide->createChartShape();
111+
$oShape->setIncludeSpreadsheet(true);
112+
/** @var AbstractType $oChart */
113+
$oChart = new $chartType();
114+
$oSeries = new Series('Downloads', $seriesData);
115+
$oChart->addSeries($oSeries);
116+
$oShape->getPlotArea()->setType($oChart);
117+
118+
$chartBaseXmlPath = sprintf('/c:chartSpace/c:chart/c:plotArea/%s', $chartElementName);
119+
120+
self::assertTrue($oShape->hasIncludedSpreadsheet());
121+
122+
$this->assertZipFileExists('ppt/charts/' . $oShape->getIndexedFilename());
123+
$this->assertZipFileExists('ppt/embeddings/' . $oShape->getIndexedFilename() . '.xlsx');
124+
125+
$this->assertZipFileExists('ppt/charts/_rels/' . $oShape->getIndexedFilename() . '.rels');
126+
$element = '/Relationships/Relationship[@Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"]';
127+
$this->assertZipXmlElementExists('ppt/charts/_rels/' . $oShape->getIndexedFilename() . '.rels', $element);
128+
129+
$element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
130+
$this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
131+
$element = $chartBaseXmlPath;
132+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
133+
$element = $chartBaseXmlPath . '/c:ser';
134+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
135+
$this->assertZipXmlElementCount('ppt/charts/' . $oShape->getIndexedFilename(), $element, 1);
136+
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:v';
137+
$this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
138+
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef';
139+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
140+
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:f';
141+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
142+
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'Sheet1!$B$1');
143+
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:strCache';
144+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
145+
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:strCache/c:pt';
146+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
147+
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:strCache/c:pt/c:v';
148+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
149+
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'Downloads');
150+
151+
$element = $chartBaseXmlPath . '/c:ser/c:val/c:numRef/c:numCache/c:pt/c:v';
152+
if ($oChart instanceof Scatter) {
153+
$element = $chartBaseXmlPath . '/c:ser/c:yVal/c:numRef/c:numCache/c:pt/c:v';
154+
}
155+
$this->assertZipXmlElementCount('ppt/charts/' . $oShape->getIndexedFilename(), $element, count($seriesData));
156+
foreach (array_values($seriesData) as $index => $value) {
157+
$this->assertZipXmlElementAtIndexEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $index, $value);
158+
}
159+
160+
$element = '/c:chartSpace/c:externalData';
161+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
162+
$this->assertZipXmlAttributeExists('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'r:id');
163+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'r:id', 'rId1');
164+
$element = '/c:chartSpace/c:externalData/c:autoUpdate';
165+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
166+
$this->assertZipXmlAttributeExists('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val');
167+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '0');
168+
169+
$this->assertIsSchemaECMA376Valid();
170+
}
171+
102172
/**
103173
* @dataProvider dataProviderIncludedSpreadsheet
104174
*/

0 commit comments

Comments
 (0)