首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache POI XSLF创建部分

Apache POI XSLF创建部分
EN

Stack Overflow用户
提问于 2016-10-28 16:49:57
回答 1查看 329关注 0票数 1

我正在为在apache POI中创建分区而苦苦挣扎。我想用幻灯片定义defina部分,我该怎么做呢?到目前为止,我可以添加幻灯片,没有任何问题。

下面是另存为XML的演示文稿的PowerPoint部分,您可以在其中查看这些部分是如何存储的:

代码语言:javascript
复制
<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中创建一个部分并向其添加幻灯片吗?如何在此之后添加多节幻灯片和单张幻灯片?感谢您的帮助。

EN

回答 1

Stack Overflow用户

发布于 2017-06-07 18:48:02

好的,我已经完成了所有的工作:)你需要创建一个默认的部分,如下所示:

代码语言:javascript
复制
    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;

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

parent.getAttributes().getNamedItem("title").getNodeValue();元素createSection(元素标题,节点父元素){ String sectionName = "";if (parent.getAttributes() != null && parent.getAttributes().getNamedItem(“标题”) != null) { sectionName = sldIdLst }节点sectionLst = sldIdLst.getParentNode().getParentNode();

代码语言:javascript
复制
    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 liek关联起来:

代码语言:javascript
复制
 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);
        }

我希望你能明白这一点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40301379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档