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())
结果截图: