国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#如何添加PPT背景

2019-10-29 21:01:14
字體:
供稿:網(wǎng)友

我們在創(chuàng)建Powerpoint文檔時,系統(tǒng)默認的幻燈片是空白背景的,很多時候我們需要自定義幻燈片背景,以達到美觀的文檔效果。在下面的示例中將介紹給PowerPoint幻燈片設(shè)置背景的方法,主要包含以下三個部分:

  • 添加純色背景
  • 添加漸變色背景
  • 添加圖片作為背景

所需工具

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)試運行程序,生成文件,如下:

C#,PPT,背景

全部代碼:

using Spire.Presentation;using Spire.Presentation.Drawing;using System.Drawing;namespace AddBackground_PPT{  class Program  {    static void Main(string[] args)    {      //實例化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í)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到c#教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 福泉市| 余姚市| 萨迦县| 五莲县| 靖宇县| 青岛市| 洞头县| 逊克县| 康平县| 泽普县| 绍兴县| 普陀区| 红安县| 和硕县| 齐河县| 六枝特区| 句容市| 舟山市| 灵璧县| 泗阳县| 中江县| 石台县| 湘西| 都江堰市| 顺昌县| 石城县| 贵德县| 个旧市| 永定县| 衡东县| 旺苍县| 即墨市| 辽宁省| 盱眙县| 湘阴县| 昌吉市| 温州市| 江门市| 南华县| 繁昌县| 大厂|