C#如何添加PPT背景
我們在創(chuàng)建Powerpoint文檔時(shí),系統(tǒng)默認(rèn)的幻燈片是空白背景的,很多時(shí)候我們需要自定義幻燈片背景,以達(dá)到美觀的文檔效果。在下面的示例中將介紹給PowerPoint幻燈片設(shè)置背景的方法,主要包含以下三個(gè)部分:
- 添加純色背景
- 添加漸變色背景
- 添加圖片作為背景
所需工具
Free Spire.Presentation for .NET 版本3.3 (社區(qū)版)
示例代碼(供參考)
步驟 1 :添加如下using指令
using Spire.Presentation; using Spire.Presentation.Drawing; using System.Drawing;
步驟 2 :創(chuàng)建文檔
Presentation ppt = new Presentation(); ppt.LoadFromFile("test.pptx");
步驟 3 :添加純色背景
//設(shè)置文檔的背景填充模式為純色填充 ppt.Slides[0].SlideBackground.Type = BackgroundType.Custom; ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Solid; ppt.Slides[0].SlideBackground.Fill.SolidColor.Color = Color.Pink;
步驟 4 :添加漸變背景色
//設(shè)置文檔的背景填充模式為漸變色填充 ppt.Slides[1].SlideBackground.Type = BackgroundType.Custom; ppt.Slides[1].SlideBackground.Fill.FillType = FillFormatType.Gradient; ppt.Slides[1].SlideBackground.Fill.Gradient.GradientStops.Append(0f, KnownColors.Yellow); ppt.Slides[1].SlideBackground.Fill.Gradient.GradientStops.Append(1f, KnownColors.Orange);
步驟 5 :添加圖片作為背景
//設(shè)置幻燈片背景色為圖片背景 ppt.Slides[2].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom; ppt.Slides[2].SlideBackground.Fill.FillType = FillFormatType.Picture; ppt.Slides[2].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch; //加載圖片作為幻燈片背景 Image img = Image.FromFile("green.png"); IImageData image = ppt.Images.Append(img); ppt.Slides[2].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;
步驟6 :保存文件
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("result.pptx");
完成代碼后,調(diào)試運(yùn)行程序,生成文件,如下:
全部代碼:
using Spire.Presentation; using Spire.Presentation.Drawing; using System.Drawing; namespace AddBackground_PPT { class Program { static void Main(string[] args) { //實(shí)例化Presentation類,加載PowerPoint文檔 Presentation ppt = new Presentation(); ppt.LoadFromFile("test.pptx"); //設(shè)置文檔的背景填充模式為純色填充 ppt.Slides[0].SlideBackground.Type = BackgroundType.Custom; ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Solid; ppt.Slides[0].SlideBackground.Fill.SolidColor.Color = Color.Pink; //設(shè)置文檔的背景填充模式為漸變色填充 ppt.Slides[1].SlideBackground.Type = BackgroundType.Custom; ppt.Slides[1].SlideBackground.Fill.FillType = FillFormatType.Gradient; ppt.Slides[1].SlideBackground.Fill.Gradient.GradientStops.Append(0f, KnownColors.Yellow); ppt.Slides[1].SlideBackground.Fill.Gradient.GradientStops.Append(1f, KnownColors.Orange); //設(shè)置幻燈片背景色為圖片背景 ppt.Slides[2].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom; ppt.Slides[2].SlideBackground.Fill.FillType = FillFormatType.Picture; ppt.Slides[2].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch; //加載圖片作為幻燈片背景 Image img = Image.FromFile("green.png"); IImageData image = ppt.Images.Append(img); ppt.Slides[2].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image; //保存并打開文檔 ppt.SaveToFile("result.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("result.pptx"); } } }
本文完。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C# 多進(jìn)程打開PPT的示例教程
- C# / VB.NET 在PPT中創(chuàng)建、編輯PPT SmartArt圖形的方法詳解
- C# 實(shí)現(xiàn)PPT 每一頁轉(zhuǎn)成圖片過程解析
- C#將PPT文件轉(zhuǎn)換成PDF文件
- C# 實(shí)現(xiàn)對PPT文檔加密、解密及重置密碼的操作方法
- C#提取PPT文本和圖片的實(shí)現(xiàn)方法
- C# 使用Free Spire.Presentation 實(shí)現(xiàn)對PPT插入、編輯、刪除表格
- 在C#里面給PPT文檔添加注釋的實(shí)現(xiàn)代碼
- C#向PPT文檔插入圖片以及導(dǎo)出圖片的實(shí)例
- C#實(shí)現(xiàn)將PPT轉(zhuǎn)換成HTML的方法
- word ppt excel文檔轉(zhuǎn)換成pdf的C#實(shí)現(xiàn)代碼
- C#/VB.NET 自定義PPT動畫路徑的步驟
相關(guān)文章
C#把EXCEL數(shù)據(jù)轉(zhuǎn)換成DataTable
這篇文章介紹了C#把EXCEL數(shù)據(jù)轉(zhuǎn)換成DataTable的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04C#實(shí)現(xiàn)主窗體最小化后出現(xiàn)懸浮框及雙擊懸浮框恢復(fù)原窗體的方法
這篇文章主要介紹了C#實(shí)現(xiàn)主窗體最小化后出現(xiàn)懸浮框及雙擊懸浮框恢復(fù)原窗體的方法,涉及C#窗體及鼠標(biāo)事件響應(yīng)的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08C#實(shí)現(xiàn)簡單的汽車租賃系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)汽車租賃系統(tǒng)的具體實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05C#(WinForm) ComboBox和ListBox添加項(xiàng)及設(shè)置默認(rèn)選擇項(xiàng)
這篇文章主要介紹了C#(WinForm) ComboBox和ListBox添加項(xiàng)及設(shè)置默認(rèn)選擇項(xiàng)的的相關(guān)資料,需要的朋友可以參考下2014-07-07.NET實(shí)現(xiàn)父窗體關(guān)閉而不影響子窗體的方法
這篇文章主要介紹了.NET實(shí)現(xiàn)父窗體關(guān)閉而不影響子窗體的方法,很實(shí)用的功能,需要的朋友可以參考下2014-08-08C# Process調(diào)用外部程序的實(shí)現(xiàn)
這篇文章主要介紹了C# Process調(diào)用外部程序的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02