-
Notifications
You must be signed in to change notification settings - Fork 526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing chartXX.xml
files in generated PPTX
#841
Comments
@dsferruzza Have you got a sample code ? |
@Progi1984 I managed to reproduce the issue with the following code (I ran it from the CLI but this does not really matter): <?php
// In composer.json, the following is required:
// "phpoffice/phppresentation": "dev-master#6e9da8968e8afe79ffa6415d8294b9864b703060",
require 'vendor/autoload.php';
use PhpOffice\PhpPresentation\DocumentLayout;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\Chart\Series;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Fill;
const FONT_NAME = 'Helvetica';
const COLORS = [
'3c4596',
'a5e6fa',
'90c8ee',
'367ca1',
];
$presentation = new PhpPresentation();
$presentation->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_SCREEN_16X9);
$titleSlide = $presentation->getActiveSlide();
$titleShape = $titleSlide->createRichTextShape()
->setHeight(300)
->setWidth(900)
->setOffsetX(30)
->setOffsetY(100)
;
$titleShape->getActiveParagraph()->getAlignment()
->setHorizontal(Alignment::HORIZONTAL_CENTER)
;
$titleTextRun = $titleShape->createTextRun('Issue #841');
$titleTextRun->getFont()->setBold(true)
->setSize(60)
->setColor(new Color(Color::COLOR_BLACK))
->setName(FONT_NAME)
->setName(FONT_NAME)
;
///////////////////////////////////////
for ($slideNumber = 1; $slideNumber <= 2; $slideNumber++) {
echo 'Creating slide #'.$slideNumber."\n";
$slide = $presentation->createSlide();
$data = [
'Duration 1 (1h)' => 60,
'Duration 2 (1h30)' => 90,
'Duration 3 (2h)' => 120,
'Duration 4 (0h30)' => 30,
];
$colors = [
0 => new Color('ff'.COLORS[0]),
1 => new Color('ff'.COLORS[1]),
2 => new Color('ff'.COLORS[2]),
4 => new Color('ff'.COLORS[3]),
];
$series1 = new Series('Durations', $data);
$series1->setLabelPosition(Series::LABEL_OUTSIDEEND);
$series1->setShowValue(false);
$series1->setShowPercentage(false);
$series1->setShowCategoryName(true);
$series1->getFont()->setName(FONT_NAME)->setSize(8);
foreach ($colors as $i => $color) {
$series1->getDataPointFill($i)
->setFillType(Fill::FILL_SOLID)
->setStartColor($color)
;
}
$series2 = new Series('Durations', $data);
$series2->setLabelPosition(Series::LABEL_OUTSIDEEND);
$series2->setShowValue(false);
$series2->setShowPercentage(false);
$series2->setShowCategoryName(true);
$series2->getFont()->setName(FONT_NAME)->setSize(8);
foreach ($colors as $i => $color) {
$series2->getDataPointFill($i)
->setFillType(Fill::FILL_SOLID)
->setStartColor($color)
;
}
$pieChart1 = new Pie();
$pieChart1->addSeries($series1);
$pieChart2 = new Pie();
$pieChart2->addSeries($series2);
$titleShape = $slide->createRichTextShape()
->setHeight(300)
->setWidth(900)
->setOffsetX(30)
->setOffsetY(20)
;
$titleShape->getActiveParagraph()->getAlignment()
->setHorizontal(Alignment::HORIZONTAL_CENTER)
;
$titleTextRun = $titleShape->createTextRun('Charts');
$titleTextRun->getFont()->setBold(true)
->setSize(60)
->setColor(new Color(Color::COLOR_BLACK))
->setName(FONT_NAME)
;
$chart1Shape = $slide->createChartShape()
->setWidth(400)
->setHeight(400)
->setOffsetX(50)
->setOffsetY(125)
;
$chart1Shape->getTitle()->setText('Chart 1'); // @phpstan-ignore-line
$chart1Shape->getPlotArea()->setType($pieChart1); // @phpstan-ignore-line
$chart1Shape->getLegend()->setVisible(false); // @phpstan-ignore-line
$chart2Shape = $slide->createChartShape()
->setWidth(400)
->setHeight(400)
->setOffsetX(500)
->setOffsetY(125)
;
$chart2Shape->getTitle()->setText('Chart 2'); // @phpstan-ignore-line
$chart2Shape->getPlotArea()->setType($pieChart2); // @phpstan-ignore-line
$chart2Shape->getLegend()->setVisible(false); // @phpstan-ignore-line
}
///////////////////////////////////////
$writer = IOFactory::createWriter($presentation, 'PowerPoint2007');
$writer->save('issue-841.pptx'); This produces the following PPTX file: issue-841.pptx As you can see, there are only two charts in the PPTX:
Opening this in LibreOffice shows that both charts in the last slide are supposed to be displayed but do not show up (probably because |
Hi!
When building a presentation that contains many charts, sometimes the generated PPTX file does not open in PowerPoint (version 2411 from Office 365).
PowerPoint asks to repair the document, but fails to do so.
Opening the same file with LibreOffice Impress (24.8.4.2) works, but at least one chart is missing (it is listed under the slide in the object navigator, but appears completely blank).
I could not find a minimal way to reproduce this issue yet, but this is definitely related to dynamic data because most of the time the same code works well and generates a valid PPTX file.
While investigating, I discovered that, when opening the PPTX as a ZIP file, a least one
ppt/charts/chartXX.xml
file is missing; for example, bothppt/charts/chart12.xml
andppt/charts/chart14.xml
are there, but noppt/charts/chart13.xml
.If I put a
ppt/charts/chart13.xml
file in the ZIP (for example by duplicating another XML chart file), it works well: PowerPoint stops complaining and both PowerPoint and LibreOffice display the presentation correctly (except that the missing chart is now a duplicate of another chart, of course).I tried to dig deeper, but I am not familiar enough with this lib's internals so I figured it could be a good idea to ask for help/pointers.
At some point I had the intuition the issue might be caused by the way charts are gathered in a hash table (maybe multiple charts are identical or similar from the hash's perspective and this results by only generating one of these chart files), but I am not sure...
Do you have any idea on how to solve or investigate further this issue?
I am using the latest commit from master (6e9da89 at the moment of writing) and PHP 8.3.
This may be the same issue as #695 but I am not sure.
The text was updated successfully, but these errors were encountered: