我們?cè)趧?chuàng)建Powerpoint文檔時(shí),系統(tǒng)默認(rèn)的幻燈片是空白背景的,很多時(shí)候我們需要自定義幻燈片背景,以達(dá)到美觀的文檔效果。在下面的示例中將介紹給PowerPoint幻燈片設(shè)置背景的方法,主要包含以下三個(gè)部分:
創(chuàng)新互聯(lián)為您提適合企業(yè)的網(wǎng)站設(shè)計(jì)?讓您的網(wǎng)站在搜索引擎具有高度排名,讓您的網(wǎng)站具備超強(qiáng)的網(wǎng)絡(luò)競(jìng)爭(zhēng)力!結(jié)合企業(yè)自身,進(jìn)行網(wǎng)站設(shè)計(jì)及把握,最后結(jié)合企業(yè)文化和具體宗旨等,才能創(chuàng)作出一份性化解決方案。從網(wǎng)站策劃到做網(wǎng)站、成都網(wǎng)站設(shè)計(jì), 我們的網(wǎng)頁設(shè)計(jì)師為您提供的解決方案。
步驟 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");
}
}
}
本文完。
如需轉(zhuǎn)載,請(qǐng)注明出處??!