如何使用Java给PPT添加动画效果
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,本篇内容主要讲解"如何使用Java给PPT添加动画效果",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"如何使用Java给PPT添加动画效果"吧!本次测试环境
千家信息网最后更新 2026年11月02日如何使用Java给PPT添加动画效果Java程序代码
本篇内容主要讲解"如何使用Java给PPT添加动画效果",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"如何使用Java给PPT添加动画效果"吧!
本次测试环境包括:
目标测试文档:Power Point 2013
编译环境:IntelliJ IDEA 2018
JDK版本:1.8.0
PPT库版本:spire.presentation.jar 4.3.2
注:在通过该PPT库来添加动画类型(AnimationEffectType)时,可添加约150种不同类型。
Java程序代码
1. 添加预设动画效果
a. 新建PPT文档,添加形状,设置动画效果
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 AddAnimationToShape { 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.CHANGE_LINE_COLOR); //保存文档 ppt.saveToFile("AddAnimationToShape.pptx", FileFormat.PPTX_2013); }}b.加载已有PPT文档,获取形状动画效果,进行动画效果设置,这里可做更为详细的动画设置,包括动画重复播放类型、次数、持续时间、延迟时间等.
import com.spire.presentation.*;import com.spire.presentation.drawing.animation.AnimationEffect;public class RepeatAnimation { public static void main(String[] args) throws Exception{ //加载测试文档 Presentation ppt = new Presentation(); ppt.loadFromFile("test.pptx"); //获取第一张幻灯片 ISlide slide = ppt.getSlides().get(0); //获取幻灯片中第一个动画效果 AnimationEffect animation = slide.getTimeline().getMainSequence().get(0); //设置动画效果循环播放类型、次数、持续时间、延迟时间 animation.getTiming().setAnimationRepeatType(AnimationRepeatType.Number); animation.getTiming().setRepeatCount(2);//设置重复次数 animation.getTiming().setDuration(2);//设置持续时间 animation.getTiming().setTriggerDelayTime(2);//设置延迟时间 //animation.getTiming().setAnimationRepeatType(AnimationRepeatType.UtilEndOfSlide);//设置动画循环播放至幻灯片末 //animation.getTiming().setAnimationRepeatType(AnimationRepeatType.UtilNextClick);//设置动画循环播放至下次点击 //保存结果文档 ppt.saveToFile("RepeatAnimation.pptx", FileFormat.PPTX_2013); ppt.dispose(); }}2. 添加自定义动画效果
import com.spire.presentation.*;import com.spire.presentation.collections.CommonBehaviorCollection;import com.spire.presentation.drawing.FillFormatType;import com.spire.presentation.drawing.animation.*;import java.awt.*;import java.awt.geom.Point2D;public class CustomAnimationPath { public static void main(String[] args) throws Exception { //创建一个空白PPT文档 Presentation ppt = new Presentation(); //获取第一张幻灯片(新建的幻灯片文档默认已包含一张幻灯片) ISlide slide = ppt.getSlides().get(0); //添加形状到幻灯片 IAutoShape shape = slide.getShapes().appendShape(ShapeType.FIVE_POINTED_STAR,new Rectangle(180, 100, 170, 170)); shape.getFill().setFillType(FillFormatType.GRADIENT); shape.getFill().getGradient().getGradientStops().append(0, KnownColors.LIGHT_PINK); shape.getFill().getGradient().getGradientStops().append(1, KnownColors.PURPLE); shape.getShapeStyle().getLineColor().setColor(Color.white); //添加动画效果,并设置动画效果类型为PATH_USER(自定义类型) AnimationEffect effect = slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.PATH_USER); //获取自定动画的CommonBehavior集合 CommonBehaviorCollection commonBehaviorCollection = effect.getCommonBehaviorCollection(); //设置动画动作运动起点及路径模式 AnimationMotion motion = (AnimationMotion)commonBehaviorCollection.get(0); motion.setOrigin(AnimationMotionOrigin.LAYOUT); motion.setPathEditMode(AnimationMotionPathEditMode.RELATIVE); //设置动作路径 MotionPath motionPath = new MotionPath(); motionPath.addPathPoints(MotionCommandPathType.MOVE_TO,new Point2D.Float[]{new Point2D.Float(0,0)},MotionPathPointsType.CURVE_AUTO,true); motionPath.addPathPoints(MotionCommandPathType.LINE_TO,new Point2D.Float[]{new Point2D.Float(0.1f,0.1f)},MotionPathPointsType.CURVE_AUTO,true); motionPath.addPathPoints(MotionCommandPathType.LINE_TO,new Point2D.Float[]{new Point2D.Float(-0.1f,0.2f)},MotionPathPointsType.CURVE_AUTO,true); motionPath.addPathPoints(MotionCommandPathType.END,new Point2D.Float[]{},MotionPathPointsType.CURVE_AUTO,true); //设置动作路径到动画 motion.setPath(motionPath); //保存文档 ppt.saveToFile("result.pptx", FileFormat.PPTX_2013); ppt.dispose(); }}到此,相信大家对"如何使用Java给PPT添加动画效果"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
动画
效果
文档
幻灯
幻灯片
时间
类型
形状
动作
次数
路径
延迟
循环
测试
内容
版本
环境
学习
不同
实用
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技名片
广东万易互联网科技有限公司惠州分公司
上海睿民互联网科技有限公司
互联网是第几次科技革命的成果
科技互联网龙头
科技互联网政务服务
美国互联网科技巨头监管
互联网科技社
互联网医疗科技
互联网科技上市公司
镁科技互联网资讯平台
青海省互联网新科技
互联网科技扶贫时间
上海科技产业互联网平台
黑云互联网科技有限公司
互联网营销推广黑科技
宁波跨境商互联网科技有限公司
数字科技和互联网金融哪个好
黑龙江互联网科技公司
北京瑞云互联网科技有限公司
厦门中拓互联网络科技有限公司
中资互联网科技
深圳互联网络科技有限公司
华中科技大学互联网
云电互联网科技
苏州大垚互联网科技
乌苏新华互联网科技做什么的
易企秀互联网科技是做什么的
科技信息时代互联网发展
上海旺乐尼互联网科技有限公司