[英]Apache POI XSLF creating section (s)
我正忙着在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中創建一個部分並附加幻燈片? 之后如何附加多個部分和單個幻燈片? 任何幫助贊賞。
好吧所以我管理了整個事情:)你需要創建一個這樣的默認部分:
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(); Node 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);
}
我希望你能得到這個想法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.