1

我正在努力在 apache POI 中创建部分。我希望能够用幻灯片定义部分,我该如何做到这一点?到目前为止,我可以毫无问题地附加幻灯片。

以下是保存为 XML 的演示文稿的 PowerPoint 部分,您可以在其中查看这些部分的存储方式:

<pkg:part pkg:name="/ppt/presentation.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml">
    <pkg:xmlData>
        <p:presentation xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" showSpecialPlsOnTitleSld="0" embedTrueTypeFonts="1" saveSubsetFonts="1">
            (... cut out unrelevant nodes...)
            <p:sldIdLst>
                <p:sldId id="296" r:id="rId10"/>
                <p:sldId id="312" r:id="rId11"/>
                <p:sldId id="274" r:id="rId12"/>
                <p:sldId id="311" r:id="rId13"/>
                <p:sldId id="275" r:id="rId14"/>
                <p:sldId id="276" r:id="rId15"/>
                <p:sldId id="317" r:id="rId16"/>
                <p:sldId id="313" r:id="rId17"/>
                <p:sldId id="318" r:id="rId18"/>
                <p:sldId id="319" r:id="rId19"/>
                <p:sldId id="307" r:id="rId20"/>
                <p:sldId id="314" r:id="rId21"/>
                <p:sldId id="315" r:id="rId22"/>
                <p:sldId id="321" r:id="rId23"/>
                <p:sldId id="320" r:id="rId24"/>
                <p:sldId id="308" r:id="rId25"/>
                <p:sldId id="322" r:id="rId26"/>
                <p:sldId id="303" r:id="rId27"/>
                <p:sldId id="264" r:id="rId28"/>
                <p:sldId id="300" r:id="rId29"/>
                <p:sldId id="287" r:id="rId30"/>
                <p:sldId id="309" r:id="rId31"/>
                <p:sldId id="289" r:id="rId32"/>
            </p:sldIdLst>

            <p:extLst>
                <p:ext uri="{521415D9-36F7-43E2-AB2F-B90AF26B5E84}">
                    <p14:sectionLst xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main">
                        <p14:section name="Default Section" id="{F7FF9A22-6035-4F7F-86B4-79EDB5AF0A91}">
                            <p14:sldIdLst>
                                <p14:sldId id="296"/>
                            </p14:sldIdLst>
                        </p14:section>
                        <p14:section name="PPT section example" id="{376F793D-518A-4B6E-AAA6-8CD5D37CFC8B}">
                            <p14:sldIdLst>
                                <p14:sldId id="312"/>
                                <p14:sldId id="274"/>
                                <p14:sldId id="311"/>
                                <p14:sldId id="275"/>
                                <p14:sldId id="276"/>
                                <p14:sldId id="317"/>
                                <p14:sldId id="313"/>
                                <p14:sldId id="318"/>
                                <p14:sldId id="319"/>
                                <p14:sldId id="307"/>
                                <p14:sldId id="314"/>
                                <p14:sldId id="315"/>
                                <p14:sldId id="321"/>
                                <p14:sldId id="320"/>
                                <p14:sldId id="308"/>
                                <p14:sldId id="322"/>
                                <p14:sldId id="303"/>
                                <p14:sldId id="264"/>
                                <p14:sldId id="300"/>
                                <p14:sldId id="287"/>
                                <p14:sldId id="309"/>
                                <p14:sldId id="289"/>
                            </p14:sldIdLst>
                        </p14:section>
                    </p14:sectionLst>
                </p:ext> (...more contents not relevant I guess ...)

有谁知道如何在 Apache POI 中创建一个部分并将幻灯片附加到它?之后如何附加多个部分和单个幻灯片?任何帮助表示赞赏。

4

1 回答 1

0

好的,所以我管理了整个事情 :) 您需要创建一个像这样的默认部分:

    CTExtensionList extensionsList = ppt.getCTPresentation().getExtLst();//create default section            
    CTExtension extension = extensionsList.insertNewExt(0);
    extension.setUri("{521415D9-36F7-43E2-AB2F-B90AF26B5E84}");
    Node ext = extension.getDomNode();
    Element sectionLst = ext.getOwnerDocument().createElementNS(p14Xmlns, "p14:sectionLst");
    sectionLst.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:p14", p14Xmlns);
    ext.appendChild(sectionLst);
    Element section = sectionLst.getOwnerDocument().createElementNS(p14Xmlns, "p14:section");
    section.setAttribute("name", "Default section");
    section.setAttribute("id", "{" + UUID.randomUUID().toString().toUpperCase() + "}");
    Element sldIdLst = section.getOwnerDocument().createElementNS(p14Xmlns, "p14:sldIdLst");
    section.appendChild(sldIdLst);
    sectionLst.appendChild(section);
    return sldIdLst;

然后,如果需要,您可以使用此方法创建其他部分:

private Element createSection(Element sldIdLst, Node parent) { String sectionName = ""; if (parent.getAttributes() != null && parent.getAttributes().getNamedItem("title") != null) { sectionName = parent.getAttributes().getNamedItem("title").getNodeValue(); } 节点sectionLst = sldIdLst.getParentNode().getParentNode();

    Element section = sectionLst.getOwnerDocument().createElementNS(p14Xmlns, "p14:section");
    section.setAttribute("name", sectionName);
    section.setAttribute("id", "{" + UUID.randomUUID().toString().toUpperCase() + "}");
    Element newSldIdLst = section.getOwnerDocument().createElementNS(p14Xmlns, "p14:sldIdLst");
    section.appendChild(newSldIdLst);
    sectionLst.appendChild(section);
    sldIdLst = newSldIdLst;
    return sldIdLst;
}

然后我不得不手动将 XSLSlide 与 sldIdLst 相关联:

 XSLFSlide slide = createSlideFromXml(parent, ppt);
        if (slide != null)
        {
            List<CTSlideIdListEntry> sldIdList = ppt.getCTPresentation().getSldIdLst().getSldIdList();
            long slideInternalId = 0;
            for (CTSlideIdListEntry entry : sldIdList)
            {
                if (entry.getId2().equals(slide.getPackageRelationship().getId()))
                {
                    slideInternalId = entry.getId();
                    break;
                }
            }
            Element sldId = sldIdLst.getOwnerDocument().createElementNS("http://schemas.microsoft.com/office/powerpoint/2010/main", "p14:sldId");
            sldId.setAttribute("id", String.valueOf(slideInternalId));
            sldIdLst.appendChild(sldId);
        }

我希望你能明白。

于 2017-06-07T10:48:01.750 回答