0

Is there any api for PPTx Sections / SlideLists?

See http://msdn.microsoft.com/en-us/library/dd907440%28v=office.12%29.aspx

If there isn't, any suggestions how to start with this?

Thanks!

fiffy
  • 840
  • 9
  • 16

2 Answers2

0

I've found a way to get the information i need.

Comments are welcome.

public static void main(String[] args) throws Exception
{
    String inputfilepath="d:\\test.pptx";
    PresentationMLPackage presentationMLPackage=(PresentationMLPackage) PresentationMLPackage.load(new java.io.File(inputfilepath));
    CTExtensionList extLst = presentationMLPackage.getMainPresentationPart().getJaxbElement().getExtLst();
    for (CTExtension extension : extLst.getExt())
    {
        if ("{521415D9-36F7-43E2-AB2F-B90AF26B5E84}".equals(extension.getUri()))
        {
            Object any = extension.getAny();
            Node sectionListNode = null;
            if (any instanceof Node && "sectionLst".equals((sectionListNode = (Node) any).getLocalName()))
            {
                for (int i = 0; i < sectionListNode.getChildNodes().getLength(); i++)
                {
                    Node sectionNode = sectionListNode.getChildNodes().item(i);
                    String sectionName = ((Element)sectionNode).getAttribute("name").toString();
                    int sectionSlides = sectionNode.getFirstChild().getChildNodes().getLength();
                    System.out.println("Section:" + sectionName + " has childs:" + sectionSlides);
                }
            }
        }
    }
}
fiffy
  • 840
  • 9
  • 16
0

The following method from org.docx4j.openpackaging.parts.PresentationML.MainPresentationPart shows how to use SldIdLst:

public SlidePart getSlide(int index) throws Pptx4jException {

    List<SldId> sldIds = this.getJaxbElement().getSldIdLst().getSldId();

    int zeroBasedCount = sldIds.size() -1; 

    if (index< 0 || index>zeroBasedCount) {
        throw new Pptx4jException("No slide at index " + index + ".  (There are " + sldIds.size() + " slides) ");           
    }

    try {
        Presentation.SldIdLst.SldId entry = this.getJaxbElement().getSldIdLst().getSldId().get(index);
        return (SlidePart)this.getRelationshipsPart().getPart(entry.getRid());
    } catch (Exception e) {
        throw new Pptx4jException("Slide " + index + " not found", e);
    }

}
JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • This has nothing to do with sections. – fiffy Jul 03 '14 at 10:33
  • Yeah well on my reading of the link you provided your question had 2 parts (since the example in the link contains p:sldIdLst). I didn't continue on to the section part because you posted your answer at the same time as I was helping you out. – JasonPlutext Jul 03 '14 at 22:49
  • Ah ok, sorry for beeing so harsh. – fiffy Jul 04 '14 at 06:11