ppt中的动画可分为内置动画及自定义动画。设置内置动画效果可参考这篇文章,本文介绍使用spire.presentation for .net来实现自定义动画效果。
c#
using spire.presentation;
using spire.presentation.collections;
using spire.presentation.drawing.animation;
using system.drawing;
namespace customanimation
{
class program
{
static void main(string[] args)
{
//创建一个幻灯片文档(新建的文档已默认包含一页幻灯片)
presentation ppt = new presentation();
islide slide = ppt.slides[0];//获取第一页空白幻灯片
//添加形状(指定形状坐标、大小及相关格式设置)
iautoshape shape = slide.shapes.appendshape(shapetype.fivepointedstar, new rectanglef(100, 50, 180, 180));
shape.fill.filltype = spire.presentation.drawing.fillformattype.gradient;
shape.fill.gradient.gradientstops.append(0, knowncolors.skyblue);
shape.fill.gradient.gradientstops.append(1, knowncolors.pink);
shape.shapestyle.linecolor.color = color.white;
//给形状设置动画效果
animationeffect effect = ppt.slides[0].timeline.mainsequence.addeffect(shape, animationeffecttype.pathuser);
commonbehaviorcollection common = effect.commonbehaviorcollection;
animationmotion motion = (animationmotion)common[0];
motion.origin = animationmotionorigin.layout;
motion.patheditmode = animationmotionpatheditmode.relative;
motionpath moinpath = new motionpath();
moinpath.add(motioncommandpathtype.moveto, new pointf[] { new pointf(0, 0) }, motionpathpointstype.curveauto, true);
moinpath.add(motioncommandpathtype.lineto, new pointf[] { new pointf(0.18f, 0.18f) }, motionpathpointstype.curveauto, true);
moinpath.add(motioncommandpathtype.lineto, new pointf[] { new pointf(-0.1f, 0.2f) }, motionpathpointstype.curveauto, true);
moinpath.add(motioncommandpathtype.lineto, new pointf[] { new pointf(0.25f, 0.2f) }, motionpathpointstype.curveauto, true);
moinpath.add(motioncommandpathtype.end, new pointf[] { }, motionpathpointstype.curvestraight, true);
motion.path = moinpath;
//保存文档
ppt.savetofile("customanimation.pptx", fileformat.pptx2013);
system.diagnostics.process.start("customanimation.pptx");
}
}
}
vb.net
imports spire.presentation
imports spire.presentation.collections
imports spire.presentation.drawing.animation
imports system.drawing
namespace customanimation
class program
private shared sub main(args as string())
'创建一个幻灯片文档(新建的文档已默认包含一页幻灯片)
dim ppt as new presentation()
'获取第一页空白幻灯片
dim slide as islide = ppt.slides(0)
'添加形状(指定形状坐标、大小及相关格式设置)
dim shape as iautoshape = slide.shapes.appendshape(shapetype.fivepointedstar, new rectanglef(100, 50, 180, 180))
shape.fill.filltype = spire.presentation.drawing.fillformattype.gradient
shape.fill.gradient.gradientstops.append(0, knowncolors.skyblue)
shape.fill.gradient.gradientstops.append(1, knowncolors.pink)
shape.shapestyle.linecolor.color = color.white
'给形状设置动画效果
dim effect as animationeffect = ppt.slides(0).timeline.mainsequence.addeffect(shape, animationeffecttype.pathuser)
dim common as commonbehaviorcollection = effect.commonbehaviorcollection
dim motion as animationmotion = directcast(common(0), animationmotion)
motion.origin = animationmotionorigin.layout
motion.patheditmode = animationmotionpatheditmode.relative
dim moinpath as new motionpath()
moinpath.add(motioncommandpathtype.moveto, new pointf() {new pointf(0, 0)}, motionpathpointstype.curveauto, true)
moinpath.add(motioncommandpathtype.lineto, new pointf() {new pointf(0.18f, 0.18f)}, motionpathpointstype.curveauto, true)
moinpath.add(motioncommandpathtype.lineto, new pointf() {new pointf(-0.1f, 0.2f)}, motionpathpointstype.curveauto, true)
moinpath.add(motioncommandpathtype.lineto, new pointf() {new pointf(0.25f, 0.2f)}, motionpathpointstype.curveauto, true)
moinpath.add(motioncommandpathtype.[end], new pointf() {}, motionpathpointstype.curvestraight, true)
motion.path = moinpath
'保存文档
ppt.savetofile("customanimation.pptx", fileformat.pptx2013)
system.diagnostics.process.start("customanimation.pptx")
end sub
end class
end namespace
自定义动画效果: