添加动画效果可以让PowerPoint文档更加生动和有吸引力。本文将介绍如何使用Spire.Presentation for Java给PowerPoint文档中的形状设置动画效果。
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.animation.AnimationEffectType;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class SetAnimation {
public static void main(String[] args) throws Exception {
//创建PowerPoint文档
Presentation ppt = new Presentation();
//添加幻灯片
ISlide slide = ppt.getSlides().get(0);
//添加一个形状到幻灯片
IAutoShape shape = slide.getShapes().appendShape(ShapeType.CUBE, new Rectangle2D.Double(50, 150, 150, 150));
shape.getFill().setFillType(FillFormatType.SOLID);
shape.getFill().getSolidColor().setColor(Color.orange);
shape.getShapeStyle().getLineColor().setColor(Color.white);
//给形状设置动画效果
slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.FADED_SWIVEL);
//保存文档
ppt.saveToFile("AddAnimationToShape.pptx", FileFormat.PPTX_2013);
}
}