MS PowerPoint演示文稿允许您创建包含文本,图像,图表,动画和其他元素的幻灯片放映。各种其他格式设置选项使您的演示文稿更具吸引力。在本文中,您将了解如何以编程方式创建此类演示文稿。您将学习如何使用C#创建具有文本,表格,图像和图表的PPTX演示文稿。
>>你可以下载Aspose.Slides for Java v20.11测试。
- 创建PowerPoint演示文稿
- 打开现有的PowerPoint演示文稿
- 将幻灯片添加到演示文稿
- 将文本添加到演示文稿的幻灯片
- 在演示文稿中创建表
- 在演示文稿中创建图表
- 在演示文稿中添加图像
用C#创建PowerPoint演示文稿
让我们开始使用Aspose.Slides for .NET创建一个空的PowerPoint演示文稿。以下是执行此操作的步骤。
- 创建Presentation类的实例。
- 使用Presentation.Save(String,SaveFormat)方法将其另存为PPTX 。
下面的代码示例演示如何在C#中创建PowerPoint演示文稿。
// Instantiate a Presentation object that represents a presentation file using (Presentation presentation = new Presentation()) { // Get the first slide ISlide slide = presentation.Slides[0]; // Add content to slide... // Save presentation presentation.Save("NewPresentation.pptx", SaveFormat.Pptx); }
在C#中打开现有的PowerPoint演示文稿
无需付出额外的努力即可打开现有的PowerPoint演示文稿。只需将PPTX文件的路径提供给Presentation类的构造函数,即可完成。下面的代码示例演示如何打开现有的PPTX演示文稿。
// Opening the presentation file by passing the file path to the constructor of Presentation class Presentation pres = new Presentation("OpenPresentation.pptx"); // Printing the total number of slides in the presentation System.Console.WriteLine(pres.Slides.Count.ToString());
将幻灯片添加到C#中的演示文稿
创建演示文稿后,就可以开始向其中添加幻灯片了。以下是使用Aspose.Slides for .NET在演示文稿中添加幻灯片的步骤。
- 创建Presentation 类的实例。
- 通过设置对Presentations.Slides属性的引用来实例化 ISlideCollection类。
- 使用ISlideCollection对象公开的Slide.AddEmptySlide (ILayoutSlide)方法将空幻灯片添加到演示文稿中
- 使用Presentation.Save(String,SaveFormat) 方法保存演示文稿文件 。
下面的代码示例演示如何使用C#在PowerPoint演示文稿中添加幻灯片。
// Instantiate Presentation class that represents the presentation file us