这篇文章主要为大家详细介绍了C#如何添加PPT背景,添加纯色背景、渐变色背景、图片背景等,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家详细介绍了C#如何添加PPT背景,添加纯色背景、渐变色背景、图片背景等,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家详细介绍了C#如何添加PPT背景,添加纯色背景、渐变色背景、图片背景等,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
我们在创建powerpoint文档时,系统默认的幻灯片是空白背景的,很多时候我们需要自定义幻灯片背景,以达到美观的文档效果。在下面的示例中将介绍给powerpoint幻灯片设置背景的方法,主要包含以下三个部分:
所需工具
free spire.presentation for .net 版本3.3 (社区版)
示例代码(供参考)
步骤 1 :添加如下using指令
|
1
2
3
|
using spire.presentation;using spire.presentation.drawing;using system.drawing; |
步骤 2 :创建文档
|
1
2
|
presentation ppt = new presentation();ppt.loadfromfile("test.pptx"); |
步骤 3 :添加纯色背景
|
1
2
3
4
|
//设置文档的背景填充模式为纯色填充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 :添加渐变背景色
|
1
2
3
4
5
|
//设置文档的背景填充模式为渐变色填充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 :添加图片作为背景
|
1
2
3
4
5
6
7
8
|
//设置幻灯片背景色为图片背景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 :保存文件
|
1
2
|
ppt.savetofile("result.pptx", fileformat.pptx2010);system.diagnostics.process.start("result.pptx"); |
完成代码后,调试运行程序,生成文件,如下:

全部代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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"); //设置文档的背景填充模式为纯色填充 ppt.slides[0].slidebackground.type = backgroundtype.custom; ppt.slides[0].slidebackground.fill.filltype = fillformattype.solid; ppt.slides[0].slidebackground.fill.solidcolor.color = color.pink; //设置文档的背景填充模式为渐变色填充 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); //设置幻灯片背景色为图片背景 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"); } }} |
本文完。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持米米素材网。
原文链接:https://www.cnblogs.com/Yesi/archive/2018/07/26/9369849.html
发表评论