1

Powerpoint slides have internal names that are accessible and modifiable via VBA. see e.g. Powerpoint: Manually set Slide Name

I would like to access the name via apache poi. I tried:

 public String getName() {
    CTSlide ctSlide = slide.getXmlObject();
    String name=ctSlide.getCSld().getName();
    return name;
  }

but only get empty strings this way if the slide names have only the default name.

What is the proper method to get (or even set) the slide name of a pptx file in Apache POI?

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186

1 Answers1

4

The slide name is by default undefined, therefore you receive an empty string. If you use your linked VBA examples and then try your code above, you get the slide name. The corresponding setter works too ...

As the slide name can be only modified over VBA - I would use the slide title instead, but depends on your use case of course.

public static void main(String[] args) throws Exception {
    // slide name has been set via VBA ...
    FileInputStream fis = new FileInputStream("slidename.pptx");
    XMLSlideShow ppt = new XMLSlideShow(fis);
    fis.close();
    XSLFSlide sl = ppt.getSlides().get(0);
    System.out.println(sl.getXmlObject().getCSld().getName());
    // set slide name via POI and validate it
    sl.getXmlObject().getCSld().setName("new name");
    FileOutputStream fos = new FileOutputStream("slidename2.pptx");
    ppt.write(fos);
    fos.close();
    ppt.close();
    fis = new FileInputStream("slidename2.pptx");
    ppt = new XMLSlideShow(fis);
    fis.close();
    System.out.println(sl.getXmlObject().getCSld().getName());
    ppt.close();
}
Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
kiwiwings
  • 3,386
  • 1
  • 21
  • 57
  • I think it is a bug that the default name is not returned as it would be in VBA. The default names seems to be "Sld"+id of slide – Wolfgang Fahl May 28 '17 at 11:55
  • This feature might apply to a potential usermodel method, but not to the underlying xmlbeans. I could add this to the API, but I'm not yet convinced that this approach makes sense. If you'd open a bugzilla entry, please also describe your use case (briefly). – kiwiwings May 29 '17 at 12:12
  • I have a JSF Jira account but nob bugzilla account - is there some kind of single sign on option? The best option would be if you'd migrate everything to github. The issue system there is much better integrated with other systems. – Wolfgang Fahl Jan 23 '18 at 17:34
  • There is a change request at https://bz.apache.org/bugzilla/show_bug.cgi?id=62037 now – Wolfgang Fahl Jan 23 '18 at 17:44
  • fixed - see https://svn.apache.org/viewvc?view=revision&revision=1831745 – Wolfgang Fahl Feb 02 '20 at 06:32