2

PresentationMLPackage presentMLPackage = PresentationMLPackage.createPackage();

    // 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が含まれるように変更しました。しかし、上記のコードを実行しても生成されません....助けていただければ幸いです

4

1 に答える 1

0

コピー/貼り付けしたコードの上部にあるコメントのとおり、コードはPresentationPropertiesPartがすでに存在していることを前提としています。

そうではないので、最初に作成する必要があります。以下はそのトリックを行うべきです:

PresentationPropertiesPart ppPart = new PresentationPropertiesPart();       
pp.addTargetPart(ppPart);
PresentationPr presProp = Context.getpmlObjectFactory().createPresentationPr();
ppPart.setJaxbElement(presProp);
于 2012-12-11T01:26:50.907 に答える