简体   繁体   English

如何使用Apache POI从Powerpoint的幻灯片图中获取DataXML

[英]How to get DataXML from Slide Diagram in Powerpoint using Apache POI

I have added one smart art shape in the Microsoft power point presentation slide. 我在Microsoft Power Point演示幻灯片中添加了一种智能艺术形状。 I want to get the data of that diagram in Java using apache POI. 我想使用apache POI在Java中获取该图的数据。

How to retrieve the complete data.xml from first slide of presentation. 如何从演示文稿的第一张幻灯片中检索完整的data.xml。 I opened the presentation and following is the hierarchy of presentation. 我打开了演示文稿,以下是演示文稿的层次结构。

在此处输入图片说明

I want to retrieve the data from first slide smart art diagram in XML ( complete data1.xml ) 我想从XML中的第一个幻灯片智能艺术图中检索数据 (完整的data1.xml)

Following is the code for getting first slide i have developed so far. 以下是到目前为止我开发的获取第一张幻灯片的代码。

public static void main(String[] args) {
    // TODO Auto-generated method stub
    final String filename = "resources/fptbenchmark/Powerpoint Import.pptx";

    try {
        XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(filename));
        ppt.getSlides()[0]. //here first slide
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

Assuming you know you'll always want /ppt/diagrams/data1.xml , then your code would want to continue with: 假设您总是需要/ppt/diagrams/data1.xml ,那么您的代码将继续:

OPCPackage pkg = ppt.getPackage();
PackagePart data1 = pkg.getPart(
       PackagingURIHelper.createPartName("/ppt/diagrams/data1.xml"));
InputStream data1Inp = data1.getInputStream();

Then pass that InputStream to your XML parsing code to process 然后将该InputStream传递到您的XML解析代码以进行处理

If you need to find the part dynamically based on the slide, you'll want to check the Relationships defined on your Slide part, and go from there 如果需要基于幻灯片动态查找零件,则需要检查在幻灯片零件上定义的“关系”,然后从那里开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM