2012-12-01 25 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