>>你可以点击这里下载Aspose.Slides 最新版测试体验。

在 ASP.NET 中创建 PowerPoint 演示文稿

1. 创建一个新的ASP.NET(MVC 或 Web 窗体) Web 应用程序。

2.通过NuGet安装Aspose.Slides for .NET API (或直接下载 DLL并添加引用)。

3. 在 ASP.NET 应用程序中使用以下代码片段来创建 PowerPoint 演示文稿并向其中添加不同的元素。

创建演示文稿的实例:

// Create an instance of presentationPresentation presentation = new Presentation();

将幻灯片添加到演示文稿:

// Get slide collectionISlideCollection slds = presentation.Slides;// Add an empty slide to the Slides collectionISlide sld = slds.AddEmptySlide(presentation.LayoutSlides[0]);

设置幻灯片背景:

// Set the background color of the first ISlide to Bluesld.Background.Type = BackgroundType.OwnBackground;sld.Background.FillFormat.FillType = FillType.Solid;sld.Background.FillFormat.SolidFillColor.Color = Color.Blue;

为幻灯片添加标题:

// Add title((IAutoShape)sld.Shapes[0]).TextFrame.Text = "Slide Title Heading";

向幻灯片添加文本:

// Add an AutoShape of Rectangle typeIAutoShape ashp = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);// Add TextFrame to the Rectangleashp.AddTextFrame(" ");// Accessing the text frameITextFrame txtFrame = ashp.TextFrame;// Create the Paragraph object for text frameIParagraph para = txtFrame.Paragraphs[0];// Create Portion object for paragraphIPortion portion = para.Portions[0];// Set Textportion.Text = "Aspose TextBox";

将图像插入幻灯片:

// Add imageIPPImage image = presentation.Images.AddImage(File.ReadAllBytes("image.png"));sld.Shapes.AddPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, image);

向幻灯片添加形状:

// Add autoshape of ellipse typesld.Shapes.AddAutoShape(ShapeType.Ellipse, 50, 150, 150, 50);

保存 PowerPoint 演示文稿:

// Save the presentation to diskpresentation.Save("presentation.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
// Load presentationPresentation presentation = new Presentation("presentation.pptx");

完整的源代码:

以下是在 ASP.NET 中创建 PowerPoint 演示文稿的完整源代码。

// Create presentationusing (Presentation presentation = new Presentation()){    // Get slide collection    ISlideCollection slds = presentation.Slides;    // Add an empty slide to the Slides collection    ISlide sld = slds.AddEmptySlide(presentation.LayoutSlides[0]);    // Set the background color of the first ISlide to Blue    sld.Background.Type = BackgroundType.OwnBackground;    sld.Background.FillFormat.FillType = FillType.Solid;    sld.Background.FillFormat.SolidFillColor.Color = Color.Blue;    // Add title    ((IAutoShape)sld.Shapes[0]).TextFrame.Text = "Slide Title Heading";    // Add an AutoShape of Rectangle type    IAutoShape ashp = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);    // Add TextFrame to the Rectangle    ashp.AddTextFrame(" ");    // Accessing the text frame    ITextFrame txtFrame = ashp.TextFrame;    // Create the Paragraph object for text frame    IParagraph para = txtFrame.Paragraphs[0];    // Create Portion object for paragraph    IPortion portion = para.Portions[0];    // Set Text    portion.Text = "Aspose TextBox";    // Add image    IPPImage image = presentation.Images.AddImage(File.ReadAllBytes("image.png"));    sld.Shapes.AddPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, image);    // Add autoshape of ellipse type    sld.Shapes.AddAutoShape(ShapeType.Ellipse, 50, 150, 150, 50);    // Save the presentation to disk    presentation.Save("presentation.pptx", Aspose.Slides.Export.SaveFormat.Pptx);}

如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。


还想要更多吗可以点击阅读【Aspose最新资源在线文库】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年8月7日
下一篇 2021年8月7日

相关推荐

发表回复

登录后才能评论