翻譯|使用教程|編輯:李顯亮|2021-09-03 09:43:10.457|閱讀 463 次
概述:在本文中,將學(xué)習(xí)如何使用 C# 以編程方式設(shè)置 PowerPoint 演示文稿中幻燈片的背景。特別地,本文將介紹如何設(shè)置普通幻燈片和母版幻燈片的背景。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在本文中,將學(xué)習(xí)如何使用 C# 以編程方式設(shè)置 PowerPoint 演示文稿中幻燈片的背景。特別地,本文將介紹如何設(shè)置普通幻燈片和母版幻燈片的背景。
為了在 PowerPoint 演示文稿中設(shè)置或更改幻燈片的背景,我們將使用Aspose.Slides for .NET,該 API 旨在創(chuàng)建、操作和轉(zhuǎn)換 PowerPoint 和 OpenOffice 演示文稿。
>>你可以點(diǎn)擊這里下載Aspose.Slides 最新版測試體驗。
以下是使用 C# 設(shè)置 PowerPoint 演示文稿中普通幻燈片背景顏色的步驟。
以下代碼示例展示了如何在 PowerPoint 演示文稿中設(shè)置幻燈片的背景。
// Instantiate the Presentation class that represents the presentation file using (Presentation pres = new Presentation("presentation.pptx")) { // Set the background color of the first ISlide to Blue pres.Slides[0].Background.Type = BackgroundType.OwnBackground; pres.Slides[0].Background.FillFormat.FillType = FillType.Solid; pres.Slides[0].Background.FillFormat.SolidFillColor.Color = Color.Blue; // Save presentation pres.Save("ContentBG_out.pptx", SaveFormat.Pptx); }
下面是設(shè)置背景前的幻燈片截圖。
以下是設(shè)置背景后的PowerPoint幻燈片。
還可以設(shè)置將影響演示文稿中所有幻燈片的母版幻燈片的背景。以下是更改母版幻燈片背景顏色的步驟。
以下代碼示例顯示了如何更改 PowerPoint 中母版幻燈片的背景。
// Instantiate the Presentation class that represents the presentation file using (Presentation pres = new Presentation("presentation.pptx")) { // Set the background color of the Master ISlide to Forest Green pres.Masters[0].Background.Type = BackgroundType.OwnBackground; pres.Masters[0].Background.FillFormat.FillType = FillType.Solid; pres.Masters[0].Background.FillFormat.SolidFillColor.Color = Color.ForestGreen; // Save presentation pres.Save("SetSlideBackgroundMaster_out.pptx", SaveFormat.Pptx); }
還可以使用 Aspose.Slides for .NET 設(shè)置幻燈片的漸變背景顏色,如下面的步驟所示。
下面的代碼示例展示了如何在 PowerPoint 中設(shè)置幻燈片的漸變背景顏色。
// Instantiate the Presentation class that represents the presentation file using (Presentation pres = new Presentation("presentation.pptx")) { // Apply Gradiant effect to the Background pres.Slides[0].Background.Type = BackgroundType.OwnBackground; pres.Slides[0].Background.FillFormat.FillType = FillType.Gradient; pres.Slides[0].Background.FillFormat.GradientFormat.TileFlip = TileFlip.FlipBoth; // Save presentation pres.Save("ContentBG_Grad_out.pptx", SaveFormat.Pptx); }
以下是使用 C# 將圖像設(shè)置為幻燈片背景的步驟。
以下代碼示例顯示了如何將圖像設(shè)置為 PowerPoint 演示文稿中的幻燈片背景。
// Instantiate the Presentation class that represents the presentation file using (Presentation pres = new Presentation("SetImageAsBackground.pptx")) { // Set the background with Image pres.Slides[0].Background.Type = BackgroundType.OwnBackground; pres.Slides[0].Background.FillFormat.FillType = FillType.Picture; pres.Slides[0].Background.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch; // Set the picture System.Drawing.Image img = (System.Drawing.Image)new Bitmap(dataDir + "Tulips.jpg"); // Add image to presentation's images collection IPPImage imgx = pres.Images.AddImage(img); pres.Slides[0].Background.FillFormat.PictureFillFormat.Picture.Image = imgx; // Save the presentation pres.Save("ContentBG_Img_out.pptx", SaveFormat.Pptx); }
如果你想試用Aspose的全部完整功能,可 聯(lián)系在線客服獲取30天臨時授權(quán)體驗。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn