Dear all,
I'm working with Apache POI and I would like to duplicate a slide containing several charts from code.
The code below (inspired by https://poi.apache.org/slideshow/xslf-cookbook.html#Merge) works fine when there is no chart on the slide.
Unfortunately, it seems that the charts are not duplicated with this method: when I try to open the resulting file, Powerpoint detects a problem, tries to repair it, but fails, and I get empty slides.
I've checked the underlying XML files (using Open XML SDK), and it seems that the chart themselves (in the folder /ppt/charts
) are not duplicated, and the relationship files (in the folder /ppt/slides/_rels
) are not completely updated.
Here is my current code:
// Open slideshow
FileInputStream fileInputStream = new FileInputStream(sourceFilePath);
XMLSlideShow slideShow = new XMLSlideShow(fileInputStream);
fileInputStream.close();
// Duplicate slide
XSLFSlideLayout layout = slide.getSlideLayout();
XSLFSlide newSlide = slideshow.createSlide(layout);
newSlide.importContent(slide);
// Save updated slideshow
FileOutputStream fileOutputStream = new FileOutputStream(outputFilePath);
slideShow.write(fileOutputStream);
fileOutputStream.close();
Do you know how I could clone a slide and its charts ?
Thanks a lot, and best regards!
Since Apache POI 4.0.0, the original code from the question will work to duplicate a slide.