翻譯|使用教程|編輯:李顯亮|2021-09-10 14:01:41.173|閱讀 436 次
概述:在本文中,將學習如何在 ASP.NET 應用程序中創建或編輯 PowerPoint 演示文稿。本文將明確介紹如何在 PowerPoint 演示文稿中添加幻燈片、標題、背景、文本、形狀和圖像。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在本文中,將學習如何在 ASP.NET 應用程序中創建或編輯 PowerPoint 演示文稿。本文將明確介紹如何在 PowerPoint 演示文稿中添加幻燈片、標題、背景、文本、形狀和圖像。
為了實現這一點,我們將使用Aspose.Slides for .NET,這是一個演示操作 API,用于創建、編輯和轉換 PowerPoint 和 OpenOffice 文件。
>>你可以點擊這里下載Aspose.Slides 最新版測試體驗。
1. 創建一個新的ASP.NET(MVC 或 Web 窗體) Web 應用程序。
2.通過NuGet安裝Aspose.Slides for .NET API (或直接下載 DLL并添加引用)。
3. 在 ASP.NET 應用程序中使用以下代碼片段來創建 PowerPoint 演示文稿并向其中添加不同的元素。
創建演示文稿的實例:
// Create an instance of presentation 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);
保存 PowerPoint 演示文稿:
// Save the presentation to disk presentation.Save("presentation.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
編輯 PowerPoint 演示文稿:
// Load presentation Presentation presentation = new Presentation("presentation.pptx");
完整的源代碼:
以下是在 ASP.NET 中創建 PowerPoint 演示文稿的完整源代碼。
// Create presentation using (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天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn