有一个叫做AnimationInfo的类,应该从Presentation提供动画信息。但是我的运气不好,我没办法。

List<XSLFShape> shapes = slide.getShapes();
for (XSLFShape shape: shapes) {
  //Need to get animation of this shape here
}


谁可以帮我这个事 ?谢谢。

PS:我正在使用3.17版本的POI。

最佳答案

如果仅添加了检测动画的功能,则可以检查工作表中的计时信息,该信息很可能标识了动画的存在,即,如果添加了动画然后再次将其删除,则可能会得到误报。此外,您需要检查所有幻灯片,直到找到动画为止。

import java.io.FileInputStream;

import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordContainer;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.xslf.usermodel.XSLFSlide;

public class AnimCheck {
    private static final int timingRecordPath[] = {
        RecordTypes.ProgTags.typeID,
        RecordTypes.ProgBinaryTag.typeID,
        RecordTypes.BinaryTagData.typeID,
        0xf144
    };


    public static void main(String[] args) throws Exception {
        SlideShow<?,?> ppt = SlideShowFactory.create(new FileInputStream("no_anim.pptx"));
        Slide<?,?> slide = ppt.getSlides().get(0);
        boolean hasTiming;
        if (slide instanceof XSLFSlide) {
            XSLFSlide xsld = (XSLFSlide)slide;
            hasTiming = xsld.getXmlObject().isSetTiming();
        } else {
            HSLFSlide hsld = (HSLFSlide)slide;
            Record lastRecord = hsld.getSheetContainer();
            boolean found = true;
            for (int ri : timingRecordPath) {
                lastRecord = ((RecordContainer)lastRecord).findFirstOfType(ri);
                if (lastRecord == null) {
                    found = false;
                    break;
                }
            }
            hasTiming = found;
        }
        ppt.close();
        System.out.println(hasTiming);
    }
}

关于java - 如何从Apache POI演示文稿获取AnimationInfo,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45649724/

10-10 01:46