powerpoint文档(幻灯片)是一种常见的演示文档,给幻灯片添加切换效果,可以使幻灯片演示时生动,有趣。本文将介绍如何通过编程的方式添加和获取幻灯片切换效果。
添加幻灯片切换效果:
c#
//创建ppt对象
presentation ppt = new presentation();
//加载文件
ppt.loadfromfile(@"input.pptx");
//获取第一张幻灯片
islide slide = ppt.slides[0];
//设置切换类型
slide.slideshowtransition.type = transitiontype.flythrough;
//设置切换声音模式
slide.slideshowtransition.soundmode = transitionsoundmode.stopprevoiussound;
//设置持续时间
slide.slideshowtransition.duration = 2000;
//设置效果选项
slide.slideshowtransition.option = transitionflythroughinoutdirection.out;
//保存文件
ppt.savetofile("transition.pptx", fileformat.pptx2010);
vb.net
'创建ppt对象
dim ppt as new presentation()
'加载文件
ppt.loadfromfile("input.pptx")
'获取第一张幻灯片
dim slide as islide = ppt.slides(0)
'设置切换类型
slide.slideshowtransition.type = transitiontype.flythrough
'设置切换声音模式
slide.slideshowtransition.soundmode = transitionsoundmode.stopprevoiussound
'设置持续时间
slide.slideshowtransition.duration = 2000
'设置效果选项
slide.slideshowtransition.[option] = transitionflythroughinoutdirection.out
'保存文件
ppt.savetofile("transition.pptx", fileformat.pptx2010)
效果动图:
获取幻灯片切换设置:
c#
//创建一个list收集获取的结果
list results = new list();
//创建ppt对象
presentation ppt = new presentation();
//加载之前的结果文件
ppt.loadfromfile("transition.pptx");
//获取第一张幻灯片
islide slide = ppt.slides[0];
//获取类型
transitiontype type = slide.slideshowtransition.type;
results.add(type.tostring());
//获取声音模式
transitionsoundmode mode = slide.slideshowtransition.soundmode;
results.add(mode.tostring());
//获取切换持续时间
uint value = slide.slideshowtransition.duration;
results.add(value.tostring());
//获取效果选项
object effect = slide.slideshowtransition.option;
results.add(effect.tostring());
vb.net
'创建一个list收集获取的结果
dim results as new list()
'创建ppt对象
dim ppt as new presentation()
'加载之前的结果文件
ppt.loadfromfile("transition.pptx")
'获取第一张幻灯片
dim slide as islide = ppt.slides(0)
'获取类型
dim type as transitiontype = slide.slideshowtransition.type
results.add(type.tostring())
'获取声音模式
dim mode as transitionsoundmode = slide.slideshowtransition.soundmode
results.add(mode.tostring())
'获取切换持续时间
dim value as uinteger = slide.slideshowtransition.duration
results.add(value.tostring())
'获取效果选项
dim effect as object = slide.slideshowtransition.[option]
results.add(effect.tostring())
结果截图: