操作PowerPoint幻灯片文档时,我们通常会需要添加或删除幻灯片。该文将详细描述如何使用Spire.Presentation添加或删除PowerPoint 幻灯片,以及如何调整PowerPoint里的幻灯片顺序。
添加新幻灯片到已有的PowerPoint文档
C#
//创建一个PowerPoint文档并加载示例文档
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx");
//在第二页插入空白幻灯片
presentation.Slides.Insert(1);
//在文档末尾添加新幻灯片
presentation.Slides.Append();
//保存文档
presentation.SaveToFile("Addnewslide.pptx", FileFormat.Pptx2010);
VB.NET
'创建一个PowerPoint文档并加载示例文档 Dim presentation As New Presentation() presentation.LoadFromFile("Sample.pptx") '在第二页插入空白幻灯片
presentation.Slides.Insert(1)
'在文档末尾添加新幻灯片 presentation.Slides.Append() '保存文档
presentation.SaveToFile("Addnewslide.pptx", FileFormat.Pptx2010)
删除指定幻灯片
C#
//创建一个PowerPoint文档并加载示例文档
Presentation presentation = new Presentation();
presentation.LoadFromFile("Addnewslide.pptx");
//删除第三张幻灯片
presentation.Slides.RemoveAt(2);
//保存文档
presentation.SaveToFile("Removeslide.pptx", FileFormat.Pptx2010);
VB.NET
'创建一个PowerPoint文档并加载示例文档 Dim presentation As New Presentation() presentation.LoadFromFile("Addnewslide.pptx") '删除第三张幻灯片
presentation.Slides.RemoveAt(2)
'保存文档 presentation.SaveToFile("Removeslide.pptx",FileFormat.Pptx2010)
调整幻灯片顺序
C#
//创建一个PowerPoint文档并加载示例文档 Presentation presentation = new Presentation();presentation.LoadFromFile("Sample.pptx");//获取文档中的第一张幻灯片并将其设置为第二张 ISlide slide = presentation.Slides[0];slide.SlideNumber = 2;//保存文档 presentation.SaveToFile("Reorder.pptx",FileFormat.Pptx2010);
VB.NET
'创建一个PowerPoint文档并加载示例文档
Dim presentation As New Presentation()
presentation.LoadFromFile("Sample.pptx")
'获取文档中的第一张幻灯片并将其设置为第二张 Dim slide As ISlide = presentation.Slides(0) slide.SlideNumber = 2 '保存文档
presentation.SaveToFile("Reorder.pptx", FileFormat.Pptx2010)