C# 如何添加PPT背景(纯色背景、渐变色背景、图片背景)
我们在创建Powerpoint文档时,系统默认的幻灯片是空白背景的,很多时候我们需要自定义幻灯片背景,以达到美观的文档效果。在下面的示例中将介绍给PowerPoint幻灯片设置背景的方法,主要包含以下三个部分:
- 添加纯色背景
 - 添加渐变色背景
 - 添加图片作为背景
 
所需工具
示例代码(供参考)
步骤 1 :添加如下using指令
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
步骤 2 :创建文档
Presentation ppt = new Presentation();
ppt.LoadFromFile("test.pptx");
步骤 3 :添加纯色背景
//设置文档的背景填充模式为纯色填充
ppt.Slides[].SlideBackground.Type = BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Solid;
ppt.Slides[].SlideBackground.Fill.SolidColor.Color = Color.Pink;
步骤 4 :添加渐变背景色
//设置文档的背景填充模式为渐变色填充
ppt.Slides[].SlideBackground.Type = BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Gradient;
ppt.Slides[].SlideBackground.Fill.Gradient.GradientStops.Append(0f, KnownColors.Yellow);
ppt.Slides[].SlideBackground.Fill.Gradient.GradientStops.Append(1f, KnownColors.Orange);
步骤 5 :添加图片作为背景
//设置幻灯片背景色为图片背景
ppt.Slides[].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;
//加载图片作为幻灯片背景
Image img = Image.FromFile("green.png");
IImageData image = ppt.Images.Append(img);
ppt.Slides[].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;
步骤6 :保存文件
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");
完成代码后,调试运行程序,生成文件,如下:

全部代码:
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[].SlideBackground.Type = BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Solid;
ppt.Slides[].SlideBackground.Fill.SolidColor.Color = Color.Pink; //设置文档的背景填充模式为渐变色填充
ppt.Slides[].SlideBackground.Type = BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Gradient;
ppt.Slides[].SlideBackground.Fill.Gradient.GradientStops.Append(0f, KnownColors.Yellow);
ppt.Slides[].SlideBackground.Fill.Gradient.GradientStops.Append(1f, KnownColors.Orange); //设置幻灯片背景色为图片背景
ppt.Slides[].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;
//加载图片作为幻灯片背景
Image img = Image.FromFile("green.png");
IImageData image = ppt.Images.Append(img);
ppt.Slides[].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image; //保存并打开文档
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");
}
}
}
本文完。
如需转载,请注明出处!!
C# 如何添加PPT背景(纯色背景、渐变色背景、图片背景)的更多相关文章
- Java设置PPT幻灯片背景——纯色、渐变、图片背景
		
PPT幻灯片生成时,系统默认是无色背景填充,幻灯片设计需要手动设置背景效果,可设置颜色填充或者图片背景填充.本文将对此介绍具体实现方法. 使用工具:Free Spire.Presentation fo ...
 - Android 设置按钮背景透明与半透明_图片背景透明
		
Button或者ImageButton的背景设为透明或者半透明 半透明<Button android:background="#e0000000" ... /> 透明 ...
 - C# 设置Word文档背景(纯色/渐变/图片背景)
		
Word是我们日常生活.学习和工作中必不可少的文档处理工具.精致美观的文档能给人带来阅读时视觉上的美感.在本篇文章中,将介绍如何使用组件Free Spire.Doc for .NET(社区版)给Wor ...
 - C# 给PDF添加图片背景
		
C# 给PDF添加图片背景 今天要实现的是给PDF文件添加图片背景这个功能.PDF是近年来最流行的文件之一,无论是办公还是日常生活中都经常会用到,很多时候,PDF文件的背景色都是白色,看多了难免觉得累 ...
 - iOS 图片背景模糊效果
		
iOS 图片背景模糊效果 1.使用CoreImage中的模糊滤镜 原始效果图如下: CoreImage的实现: - (void)viewDidLoad { [super viewDidLoad]; / ...
 - Atitit 动态按钮图片背景颜色与文字组合解决方案
		
Atitit 动态按钮图片背景颜色与文字组合解决方案 转换背景颜色,setFont("cywe_img", fontScale, 50, 5) 设置文字大小与坐标 文字分拆,使用字 ...
 - CSS背景100%平铺 浏览器缩小背景显示不全解决办法
		
本文我们分享前端CSS背景100%平铺,浏览器缩小背景显示不全bug解决的两个方法,如果你也遇到了,那么就可以参考下面文章. 把浏览器的窗口缩小时,拖动滚动条时你会发现原本设定的CSS背景100%平铺 ...
 - IOS中设置cell的背景view和选中时的背景view 、设置cell最右边的指示器(比如箭头\文本标签)
		
一.Cell的设置 1.设置cell的背景view和选中时的背景view UIImageView *bg = [[UIImageView alloc] init]; bg.image = [UIIma ...
 - jquery 图片背景透明度(支持IE5/IE6/IE7)
		
设置背景图片,以突出透明度的效果及jquery png背景透明插件实例教程 <head> <title>toggle()</title> <style typ ...
 
随机推荐
- [LeetCode] Rectangle Overlap 矩形重叠
			
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...
 - Web版需求征集系统所得2,servlet中request.getParameter获值乱码问题解决
			
servlet获值乱码问题解决 解决办法一(最简单有效) request.setCharacterEncoding("utf-8"); 解决办法二 因为乱码问题的产生是因为默认格式 ...
 - 关于AngularJS学习整理---核心特性
			
接触.学习AngularJS已经三个多月了,随着学习的深入,有些东西刚开始不明白,现在开始慢慢明白起来.于是,开始整理这几个月的学习成果.要不又要忘了... 初学Angular,是看到慕课网大漠穷秋 ...
 - Python连接MySQL数据库之pymysql模块使用
			
安装PyMySQL pip install pymysql PyMySQL介绍 PyMySQL是在python3.x版本中用于连接MySQL服务器的一个库,2中则使用mysqldb. Django中也 ...
 - Java面试中笔试题——Java代码真题,这些题会做,笔试完全可拿下!
			
大家好,我是上海尚学堂Java培训老师,以下这些Java笔试真题是上海尚学堂Java学员在找工作中笔试遇到的真题.现在分享出来,也写了参考答案,供大家学习借鉴.想要更多学习资料和视频请留言联系或者上海 ...
 - [Swift]LeetCode221. 最大正方形 | Maximal Square
			
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and re ...
 - [Swift]LeetCode762. 二进制表示中质数个计算置位 | Prime Number of Set Bits in Binary Representation
			
Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime ...
 - 读取Json,并替换json中的指定字符
			
string jsonfile = @"E:\history.json";//JSON文件路径 using (System.IO.FileStream file = new Fil ...
 - React 实现拖拽功能
			
实现效果:(可戳 https://codepen.io/wenr/pen/EGEQxp 查看) 因为工作中会用到 JIRA 所以想实现一下相似的功能,顺便学习一下 H5 的拖拽.不支持拖拽改变顺序,感 ...
 - VMware虚拟机安装Linux系统
			
许多新手连 Windows 的安装都不太熟悉,更别提 Linux 的安装了:即使安装成功了,也有可能破坏现有的 Windows 系统,比如导致硬盘数据丢失.Windows 无法开机等.所以一直以来,安 ...