2012-12-01 30 views
2

PresentationMLPackage presentationMLPackage = PresentationMLPackage.createPackage();无法获取我生成的PPTX文档中的presProps.xml

// Need references to these parts to create a slide 
    // Please note that these parts *already exist* - they are 
    // created by createPackage() above. See that method 
    // for instruction on how to create and add a part. 
    MainPresentationPart pp = (MainPresentationPart)presentationMLPackage.getParts().getParts().get(
      new PartName("/ppt/presentation.xml"));  
    SlideLayoutPart layoutPart = (SlideLayoutPart)presentationMLPackage.getParts().getParts().get(
      new PartName("/ppt/slideLayouts/slideLayout1.xml")); 

    PresentationPropertiesPart presProp = (PresentationPropertiesPart)presentationMLPackage.getParts().getParts().get(
      new PartName("/ppt/preseProps.xml")); 

    // OK, now we can create a slide 
    SlidePart slidePart = presentationMLPackage.createSlidePart(pp, layoutPart, 
      new PartName("/ppt/slides/slide1.xml")); 

    // Create and add shape 
    Shape sample = ((Shape)XmlUtils.unmarshalString(SAMPLE_SHAPE, Context.jcPML)); 
    slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(sample); 

    // All done: save it 
    presentationMLPackage.save(new java.io.File(outputfilepath)); 

    System.out.println("\n\n done .. saved " + outputfilepath); 

我已经使用上面的CreateHelloworld.java示例来创建一个pptx文档。我已经修改了它,以便创建的pptx包具有presProps.xml。但它不会产生当我执行上述代码....任何帮助将不胜感激

回答

0

根据代码顶部的评论你有复制/粘贴,你的代码假设PresentationPropertiesPart已经存在。

它没有,所以你必须先创建它。以下应该做的伎俩:

PresentationPropertiesPart ppPart = new PresentationPropertiesPart();  
pp.addTargetPart(ppPart); 
PresentationPr presProp = Context.getpmlObjectFactory().createPresentationPr(); 
ppPart.setJaxbElement(presProp); 
+0

:感谢您的信息... – freeky9

+0

不用担心。请勾选此为正确答案。 – JasonPlutext