Skip to content

Commit

Permalink
Fix column indices for embedded spreadsheets
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Roth committed Aug 2, 2021
1 parent 7932eb1 commit f2c05bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,20 @@ public function writeSpreadsheet(PhpPresentation $presentation, Chart $chart, st
$seriesIndex = 0;
foreach ($chart->getPlotArea()->getType()->getSeries() as $series) {
// Title
$sheet->setCellValueByColumnAndRow(1 + $seriesIndex, 1, $series->getTitle());
$sheet->setCellValueByColumnAndRow(2 + $seriesIndex, 1, $series->getTitle());

// X-axis
$axisXData = array_keys($series->getValues());
$numAxisXData = count($axisXData);
for ($i = 0; $i < $numAxisXData; ++$i) {
$sheet->setCellValueByColumnAndRow(0, $i + 2, $axisXData[$i]);
$sheet->setCellValueByColumnAndRow(1, $i + 2, $axisXData[$i]);
}

// Y-axis
$axisYData = array_values($series->getValues());
$numAxisYData = count($axisYData);
for ($i = 0; $i < $numAxisYData; ++$i) {
$sheet->setCellValueByColumnAndRow(1 + $seriesIndex, $i + 2, $axisYData[$i]);
$sheet->setCellValueByColumnAndRow(2 + $seriesIndex, $i + 2, $axisYData[$i]);
}

++$seriesIndex;
Expand Down Expand Up @@ -723,7 +723,7 @@ protected function writeTypeArea(XMLWriter $objWriter, Area $subject, bool $incl

// c:ser > c:tx
$objWriter->startElement('c:tx');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : '');
$this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -768,7 +768,7 @@ protected function writeTypeArea(XMLWriter $objWriter, Area $subject, bool $incl

// c:val
$objWriter->startElement('c:val');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : '');
$this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -831,7 +831,7 @@ protected function writeTypeBar(XMLWriter $objWriter, Bar $subject, bool $includ

// c:tx
$objWriter->startElement('c:tx');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : '');
$this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -967,7 +967,7 @@ protected function writeTypeBar(XMLWriter $objWriter, Bar $subject, bool $includ

// c:val
$objWriter->startElement('c:val');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : '');
$this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -1049,7 +1049,7 @@ protected function writeTypeBar3D(XMLWriter $objWriter, Bar3D $subject, bool $in

// c:tx
$objWriter->startElement('c:tx');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : '');
$this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -1170,7 +1170,7 @@ protected function writeTypeBar3D(XMLWriter $objWriter, Bar3D $subject, bool $in

// c:val
$objWriter->startElement('c:val');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : '');
$this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -1237,7 +1237,7 @@ protected function writeTypeDoughnut(XMLWriter $objWriter, Doughnut $subject, bo

// c:tx
$objWriter->startElement('c:tx');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : '');
$this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -1269,7 +1269,7 @@ protected function writeTypeDoughnut(XMLWriter $objWriter, Doughnut $subject, bo

// c:val
$objWriter->startElement('c:val');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : '');
$this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -1396,7 +1396,7 @@ protected function writeTypePie(XMLWriter $objWriter, Pie $subject, bool $includ

// c:tx
$objWriter->startElement('c:tx');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : '');
$this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -1514,7 +1514,7 @@ protected function writeTypePie(XMLWriter $objWriter, Pie $subject, bool $includ

// c:val
$objWriter->startElement('c:val');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : '');
$this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -1561,7 +1561,7 @@ protected function writeTypePie3D(XMLWriter $objWriter, Pie3D $subject, bool $in

// c:tx
$objWriter->startElement('c:tx');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : '');
$this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -1673,7 +1673,7 @@ protected function writeTypePie3D(XMLWriter $objWriter, Pie3D $subject, bool $in

// c:val
$objWriter->startElement('c:val');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : '');
$this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -1720,7 +1720,7 @@ protected function writeTypeLine(XMLWriter $objWriter, Line $subject, bool $incl

// c:tx
$objWriter->startElement('c:tx');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : '');
$this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -1822,7 +1822,7 @@ protected function writeTypeLine(XMLWriter $objWriter, Line $subject, bool $incl

// c:val
$objWriter->startElement('c:val');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : '');
$this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -1895,7 +1895,7 @@ protected function writeTypeScatter(XMLWriter $objWriter, Scatter $subject, bool

// c:tx
$objWriter->startElement('c:tx');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : '');
$this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords);
$objWriter->endElement();

Expand Down Expand Up @@ -2006,7 +2006,7 @@ protected function writeTypeScatter(XMLWriter $objWriter, Scatter $subject, bool

// c:yVal
$objWriter->startElement('c:yVal');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : '');
$coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : '');
$this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords);
$objWriter->endElement();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function testChartIncludeSpreadsheet(): void
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:tx/c:strRef/c:f';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'Sheet1!$A$1');
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'Sheet1!$B$1');
$element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:tx/c:strRef/c:strCache';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:tx/c:strRef/c:strCache/c:pt';
Expand Down

0 comments on commit f2c05bf

Please sign in to comment.