PPTx Sections / SlideLists有没有api?
请参阅http://msdn.microsoft.com/en-us/library/dd907440%28v=office.12%29.aspx
如果没有,有任何建议如何开始?
谢谢!
答案 0 :(得分:0)
我找到了获取所需信息的方法。
欢迎提出意见。
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);
}
}
}
}
}
答案 1 :(得分:0)
org.docx4j.openpackaging.parts.PresentationML.MainPresentationPart中的以下方法显示了如何使用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);
}
}