服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C# - C#如何添加PPT背景

C#如何添加PPT背景

2022-02-27 15:41E-iceblue C#

这篇文章主要为大家详细介绍了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");

完成代码后,调试运行程序,生成文件,如下:

C#如何添加PPT背景

全部代码:

?
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

延伸 · 阅读

精彩推荐
  • C#Unity3D实现虚拟按钮控制人物移动效果

    Unity3D实现虚拟按钮控制人物移动效果

    这篇文章主要为大家详细介绍了Unity3D实现虚拟按钮控制人物移动效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一...

    shenqingyu060520232410972022-03-11
  • C#C#裁剪,缩放,清晰度,水印处理操作示例

    C#裁剪,缩放,清晰度,水印处理操作示例

    这篇文章主要为大家详细介绍了C#裁剪,缩放,清晰度,水印处理操作示例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    吴 剑8332021-12-08
  • C#WPF 自定义雷达图开发实例教程

    WPF 自定义雷达图开发实例教程

    这篇文章主要介绍了WPF 自定义雷达图开发实例教程,本文介绍的非常详细,具有参考借鉴价值,需要的朋友可以参考下...

    WinterFish13112021-12-06
  • C#深入解析C#中的交错数组与隐式类型的数组

    深入解析C#中的交错数组与隐式类型的数组

    这篇文章主要介绍了深入解析C#中的交错数组与隐式类型的数组,隐式类型的数组通常与匿名类型以及对象初始值设定项和集合初始值设定项一起使用,需要的...

    C#教程网6172021-11-09
  • C#C#通过KD树进行距离最近点的查找

    C#通过KD树进行距离最近点的查找

    这篇文章主要为大家详细介绍了C#通过KD树进行距离最近点的查找,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    帆帆帆6112022-01-22
  • C#C#设计模式之Visitor访问者模式解决长隆欢乐世界问题实例

    C#设计模式之Visitor访问者模式解决长隆欢乐世界问题实例

    这篇文章主要介绍了C#设计模式之Visitor访问者模式解决长隆欢乐世界问题,简单描述了访问者模式的定义并结合具体实例形式分析了C#使用访问者模式解决长...

    GhostRider9502022-01-21
  • C#C#实现XML文件读取

    C#实现XML文件读取

    这篇文章主要为大家详细介绍了C#实现XML文件读取的相关代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    Just_for_Myself6702022-02-22
  • C#C# 实现对PPT文档加密、解密及重置密码的操作方法

    C# 实现对PPT文档加密、解密及重置密码的操作方法

    这篇文章主要介绍了C# 实现对PPT文档加密、解密及重置密码的操作方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下...

    E-iceblue5012022-02-12