1

This is my use-case:

I have two power-point files. I want to copy all of the slide templates from one powerpoint to other. I could not find any API like createTemplate() in MasterSlide, so in order to do it, I create a new XSLFSlideLayout using one of the template's (which exist in the same powerpoint) PackagePart and then using importContent() to it, to copy the template from other powerpoint. Here is a short version of it :

XMLSlideShow xmlSlideShow1 = new XMLSlideShow(templateInputStream1);
XMLSlideShow XmlSlideShow2 = new XMLSlideShow(templateInputStream2);
XSLFSlideLayout newLayout = null;

try {
  newLayout = new XSLFSlideLayout(xmlSlideShow1.getSlideMasters().get(0).getSlideLayouts().get(0).getPackagePart());
} catch (IOException | XmlException e){
  LOGGER.error("Unable to create new layout", e);
}
// breaks here
newLayout.importContent(xmlSlideShow2.getSlideMasters().get(0).getSlideLayouts().get(0));
return userXmlSlideShow.createSlide(newLayout);

And it breaks when importContent is called:

java.lang.IllegalStateException: SlideMaster was not found for Name: /ppt/slideLayouts/slideLayout1.xml - Content Type: application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml at org.apache.poi.xslf.usermodel.XSLFSlideLayout.getSlideMaster(XSLFSlideLayout.java:98) at org.apache.poi.xslf.usermodel.XSLFSlideLayout.getMasterSheet(XSLFSlideLayout.java:105) at org.apache.poi.xslf.usermodel.XSLFSlideLayout.getMasterSheet(XSLFSlideLayout.java:36) at org.apache.poi.xslf.usermodel.XSLFShape.fetchShapeProperty(XSLFShape.java:307) at org.apache.poi.xslf.usermodel.XSLFSimpleShape.getXfrm(XSLFSimpleShape.java:133) at org.apache.poi.xslf.usermodel.XSLFSimpleShape.setAnchor(XSLFSimpleShape.java:169) at org.apache.poi.xslf.usermodel.XSLFShape.copy(XSLFShape.java:137) at org.apache.poi.xslf.usermodel.XSLFSimpleShape.copy(XSLFSimpleShape.java:711) at org.apache.poi.xslf.usermodel.XSLFTextShape.copy(XSLFTextShape.java:588) at org.apache.poi.xslf.usermodel.XSLFSheet.importContent(XSLFSheet.java:372)

I'm using poi-3.15. Any leads would be of great help.

grizzly
  • 588
  • 4
  • 12

0 Answers0