powerpoint文档(幻灯片)是一种常见的演示文档,如果能给形状添加动画,演示时就显得生动,有趣。本文将介绍如何通过编程的方式给powerpoint文档里的形状添加动画,获取动画。
添加动画
c#
//创建一个ppt对象
presentation ppt = new presentation();
//获取第一张幻灯片
islide slide = ppt.slides[0];
//添加一个形状,设置填充色颜色,添加文本
iautoshape shape = slide.shapes.appendshape(shapetype.rectangle, new rectanglef(50, 50, 200, 80));
shape.fill.filltype = fillformattype.solid;
shape.fill.solidcolor.color = color.lightblue;
shape.shapestyle.linecolor.color = color.white;
shape.appendtextframe("set animation");
//给形状添加动画
animationeffect effect = shape.slide.timeline.mainsequence.addeffect(shape, animationeffecttype.fadedswivel);
//设置持续时间
effect.timing.duration = 2;
//设置重复次数
effect.timing.repeatcount = 2;
//设置动画文本效果
effect.iteratetype = spire.presentation.drawing.timeline.animatetype.letter;
//设置动画文本字符之间延迟时间
effect.iteratetimevalue = 2;
//保存文件
ppt.savetofile("setanimations.pptx", fileformat.pptx2010);
vb.net
'创建一个ppt对象
dim ppt as new presentation()
'获取第一张幻灯片
dim slide as islide = ppt.slides(0)
'添加一个形状,设置填充色颜色,添加文本
dim shape as iautoshape = slide.shapes.appendshape(shapetype.rectangle, new rectanglef(50, 50, 200, 80))
shape.fill.filltype = fillformattype.solid
shape.fill.solidcolor.color = color.lightblue
shape.shapestyle.linecolor.color = color.white
shape.appendtextframe("set animation")
'给形状添加动画
dim effect as animationeffect = shape.slide.timeline.mainsequence.addeffect(shape, animationeffecttype.fadedswivel)
'设置持续时间
effect.timing.duration = 2
'设置重复次数
effect.timing.repeatcount = 2
'设置动画文本效果
effect.iteratetype = spire.presentation.drawing.timeline.animatetype.letter
'设置动画文本字符之间延迟时间
effect.iteratetimevalue = 2
'保存文件
ppt.savetofile("setanimations.pptx", fileformat.pptx2010)
效果展示:
获取动画
c#
stringbuilder sb = new stringbuilder();
//加载ppt文件
presentation ppt = new presentation("setanimations.pptx",fileformat.pptx2010);
islide slide = ppt.slides[0];
//获取动画集合
animationeffectcollection animations = slide.timeline.mainsequence;
//获取动画的效果
animationeffecttype effecttype = animations[0].animationeffecttype;
sb.append("animation type:" effecttype.tostring() "\r\n");
//获取动画持续时间
float duration = animations[0].timing.duration;
sb.append("duration:" duration.tostring() "\r\n");
//获取动画重复次数
float count = animations[0].timing.repeatcount;
sb.append("repeat count:" count "\r\n");
//获取动画文本效果
var iteratetype = animations[0].iteratetype;
sb.append("iterate type:" iteratetype.tostring() "\r\n");
//保存结果
file.writealltext("result.txt", sb.tostring());
vb.net
dim sb as new stringbuilder()
'加载ppt文件
dim ppt as new presentation("setanimations.pptx", fileformat.pptx2010)
dim slide as islide = ppt.slides(0)
'获取动画集合
dim animations as animationeffectcollection = slide.timeline.mainsequence
'获取动画的效果
dim effecttype as animationeffecttype = animations(0).animationeffecttype
sb.append("animation type:" effecttype.tostring() vbcr & vblf)
'获取动画持续时间
dim duration as single = animations(0).timing.duration
sb.append("duration:" duration.tostring() vbcr & vblf)
'获取动画重复次数
dim count as single = animations(0).timing.repeatcount
sb.append("repeat count:" count vbcr & vblf)
'获取动画文本效果
dim iteratetype = animations(0).iteratetype
sb.append("iterate type:" iteratetype.tostring() vbcr & vblf)
'保存结果
file.writealltext("result.txt", sb.tostring())
结果: