To demonstrate our problem we created a demo code.
with version 18.7, when one slide is copied (clone method) from a template into another PowerPoint template file, not every data is displayed or no data displayed at all on the PowerPoint charts. We have to open the downloaded PowerPoint file and manually edit these charts to appear the data.
The below demo is working with two template.
We add one slide from the 2nd template to the 1st template. For the simplicity the code overwrites the demo data with itself. Our problem is also occurs with this simple example.
Please find on below link the code and the source and target ppt files, and also our running result with version 17.8 and with version 18.7
Thank you, let me know if you need something else
/**
* @Route(name="aspose", path="/aspose")
*
* @return Response
*
* @throws SiqException
* @throws \java_IllegalArgumentException
* @throws \java_IllegalStateException
*/
public function asposeDemoAction(): Response
{
$fileName = 'report.pptx';
$templateFileTarget = '/home/weinacht/DBV/siq/PPT/templates/target.pptx';
$templateFileSource = '/home/weinacht/DBV/siq/PPT/templates/source.pptx';
// Init JavaBridge and Aspose.Slides services. It is not important for demonstrate our problem.
$this->get('dbv.siq.javabridge');
$this->get('dbv.siq.aspose.slides');
// Open target presentation
$presentationTarget = new Java('com.aspose.slides.Presentation', $templateFileTarget);
$targetPresentationSlides = $presentationTarget->getSlides();
// Open second presentation
$presentationSource = new Java('com.aspose.slides.Presentation', $templateFileSource);
// Get the slides of source presentation
$sourcePresentationSlides = $presentationSource->getSlides();
$numberOfSlides = java_values($sourcePresentationSlides->size());
//Iterating through all slides
for ($i = 1; $i <= $numberOfSlides; $i++)
{
$slide = $sourcePresentationSlides->get_Item($i - 1);
// Replace chart Content
// Get all charts from slide
$shapes = $slide->getShapes();
$shapeList = (array) java_values($shapes->toArray());
$charts = [];
foreach ($shapeList as $shape) {
if (java_instanceof($shape, Java('com.aspose.slides.Chart'))) {
$charts[] = $shape;
}
}
// Iterating through all charts
foreach ($charts as $chart) {
$seriesCollection = $chart->getChartData()->getSeries();
$categoryCollection = $chart->getChartData()->getCategories();
$seriesNumbers = java_values($seriesCollection->size());
$categoryNumbers = java_values($categoryCollection->size());
// Traverse through every chart categories
$valueToWriteToCell = null;
for ($categoryIndex = 0; $categoryIndex < $categoryNumbers; ++$categoryIndex) {
$category = $categoryCollection->get_Item($categoryIndex);
if (java_values($category->getUseCell())) {
$categoryCell = $category->getAsCell();
$categoryCell->setValue(java_values($categoryCell->getValue()));
}
}
// Traverse through every chart series
$actSeriesIndex = null;
for ($seriesIndex = 0; $seriesIndex < $seriesNumbers; ++$seriesIndex) {
$seriesHaveData[$seriesIndex] = false;
$series = $seriesCollection->get_Item($seriesIndex);
$series->setInvertIfNegative(false);
// Set series cell's
$seriesCellCollection = $series->getName()->getAsCells();
$seriesCellNumber = java_values($seriesCellCollection->getCount());
for ($seriesCellIndex = 0; $seriesCellIndex < $seriesCellNumber; ++$seriesCellIndex) {
$seriesCell = $seriesCellCollection->get_Item($seriesCellIndex);
$seriesCell->setValue(java_values($seriesCell->getValue()));
}
// Get series dataPointCollection
$dataPointCollection = $series->getDataPoints();
$dataPointNumbers = java_values($dataPointCollection->size());
// Traverse through every series's dataPointCollection
$valueToWriteToCell = null;
for ($dataPointIndex = 0; $dataPointIndex < $dataPointNumbers; ++$dataPointIndex) {
$dataPoint = $dataPointCollection->get_Item($dataPointIndex);
// Set dataPoint's label
$dataLabel = $dataPoint->getLabel();
$dataLabelTextFrame = $dataLabel->getTextFrameForOverriding();
$dataLabelTextFrame->setText(java_values($dataLabelTextFrame->getText()));
// Set dataPoint's value (cell)
if (java_values($dataPointCell = $dataPoint->getValue()->getAsCell())) {
// The two replace add the same result.
// Replace by data point cell
try {
$data = java_values($dataPointCell->getValue());
$dataPointCell->setValue($data);
} catch (\JavaException $exception) {
// Nothing to do. This code is just demonstrate a problem.
}
// Replace by data point value
// $dataValue = $dataPoint->getXValue();
// $dataValue->setData(java_values($dataValue->getData()));
}
// Set dataPoint's Xvalue (cell)
if (java_values($dataPointCell = $dataPoint->getXValue()->getAsCell())) {
// The two replace add the same result.
// Replace by data point cell
try {
$data = java_values($dataPointCell->getValue());
$dataPointCell->setValue($data);
} catch (\JavaException $exception) {
// Nothing to do. This code is just demonstrate a problem.
}
// Replace by data point value
// $dataValue = $dataPoint->getXValue();
// $dataValue->setData(java_values($dataValue->getData()));
}
// Set dataPoint's Yvalue (cell)
if (java_values($dataPointCell = $dataPoint->getYValue()->getAsCell())) {
// The two replace add the same result.
// Replace by data point cell
try {
$data = java_values($dataPointCell->getValue());
$dataPointCell->setValue($data);
} catch (\JavaException $exception) {
// Nothing to do. This code is just demonstrate a problem.
}
// Replace by data point value
// $dataValue = $dataPoint->getXValue();
// $dataValue->setData(java_values($dataValue->getData()));
}
}
}
}
// Clone slide
$targetPresentationSlides->addClone($slide);
}
// Get presentation
$save_format = Java('com.aspose.slides.SaveFormat');
$memoryStream = new Java('java.io.ByteArrayOutputStream');
$presentationTarget->save($memoryStream, $save_format->Pptx);
$memoryStream->close();
$presentationContent = java_values($memoryStream->toByteArray());
// Create the response
try {
$response = new Response($presentationContent, 200);
} catch (\Exception $exception) {
throw new SiqException('Presentation export issue.', 0, $exception);
}
// Adding headers
$response->headers->set('Content-Type', 'application/vnd.ms-powerpoint');
$response->headers->set('Content-Disposition', 'attachment;filename="' .$fileName. '"');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'max-age=1');
return $response;
}