Spire.Cloud.Word.Sdk提供了接口SetBackgroudColor()、SetBackgroudImage()、DeleteBackground()、GetBackgroudColor()用于设置、删除及读取Word文档背景。本文将以C#程序为例演示如何来调用API接口实现以上内容操作。

必要步骤:

步骤一:dll文件获取及导入。通过官网下载SDK文件包。

下载后,解压文件,将Spire.Cloud.Word.Sdk.dll文件及其他三个dll添加引用至VS程序(如下图);或者在程序中通过Nuget搜索安装,直接导入。

步骤二:App ID及Key获取。云端创建账号,并在“我的应用”板块中创建应用以获得App ID及App Key。

步骤三:源文档上传。在“文档管理”板块,上传源文档。这里如果想方便文档管理,可以新建文件夹,将源文档及结果文档分别保存至相应的文件夹下。不建文件夹时,源文档及结果文档直接保存在根目录。本文示例中,建了两个文件夹,分别用于存放源文档及结果文档。

【示例1】设置背景颜色

using Spire.Cloud.Word;
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Model;
using System; namespace BackgroundColor
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static void Main(string[] args)
{
//配置账号信息
Configuration wordConfiguration = new Configuration(appId, appKey); //创建BackgroundApi实例
BackgroundApi backgroundApi = new BackgroundApi(wordConfiguration); //源文档
var fileName = "testfile.docx";
string name = fileName; //源文档所在文件夹,若没有文件夹则设置为null
string folder = "input"; //设置背景颜色RGB值
Color color = new Color(, , ); //设置文档密码,如果没有密码,则设置为null
string password = null; //使用冰蓝云配置的2G空间存贮文档,可设置为null
string storage = null; //设置生成文档的路径及文档名称
string destFilePath = "output/BackgroundColor.docx"; //调用方法设置背景颜色
backgroundApi.SetBackgroudColor(name,color, folder, storage, password, destFilePath);
}
}
}

背景颜色设置结果:

【示例2】设置背景图片

using Spire.Cloud.Word.Sdk;
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
using System; namespace BackgroundImg
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static void Main(string[] args)
{
//配置账号信息
Configuration wordConfiguration = new Configuration(appId, appKey); //创建BackgroundApi实例
BackgroundApi backgroundApi = new BackgroundApi(wordConfiguration); //源文档及图片
var fileName = "testfile.docx";
var imageName = "ss.png";
string name = fileName; //源文档所在文件夹,若没有文件夹则设置为null
string folder = "input";
string imagePath = "input" + "/"+ imageName; //设置文档密码,如果没有密码,则设置为null
string password = null; //使用冰蓝云配置的2G空间存贮文档,可设置为null
string storage = null; //设置生成文档的路径及文档名称
string destFilePath = "output/BackgroundImg.docx"; //调用方法设置背景
backgroundApi.SetBackgroudImage(name, imagePath, folder, storage, password, destFilePath);
}
}
}

背景图片设置效果:

【示例3】删除背景(包括背景颜色及背景图片)

using Spire.Cloud.Word.Sdk;
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
using System; namespace DeleteBackground
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static void Main(string[] args)
{
//配置账号信息
Configuration wordConfiguration = new Configuration(appId, appKey); //创建BackgroundApi实例
BackgroundApi backgroundApi = new BackgroundApi(wordConfiguration); //源文档
var fileName = "BackgroundImg.docx";
string name = fileName; //源文档所在文件夹,若没有文件夹则设置为null
string folder = "output"; //设置文档密码,如果没有密码,则设置为null
string password = null; //使用冰蓝云配置的2G空间存贮文档,可设置为null
string storage = null; //设置生成文档的路径及文档名称
string destFilePath = "output/DeleteBackground.docx"; //调用方法删除文档中背景
backgroundApi.DeleteBackground(name, password, folder, storage, destFilePath);
}
}
}

文档背景删除效果:

【示例4】读取背景颜色

using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Model;
using System; namespace GetBackground
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static void Main(string[] args)
{
//配置账号信息
Configuration wordConfiguration = new Configuration(appId, appKey); //创建BackgroundApi实例
BackgroundApi backgroundApi = new BackgroundApi(wordConfiguration); //源文档
var fileName = "BackgroundColor.docx";
string name = fileName; //源文档密码,若无密码可设置为null
string password = null; //源文档所在文件夹,若没有文件夹则设置为null
string folder = "output"; //使用冰蓝云配置的2G空间存贮文档,可设置为null
string storage = null; //获取文档背景色
System.Console.WriteLine(backgroundApi.GetBackgroudColor(name, password, folder, storage));
System.Console.ReadLine();
}
}
}

背景色RGB值读取结果:

(本文完)

C# 设置、删除、读取Word文档背景——基于Spire.Cloud.Word的更多相关文章

  1. C# 添加文本、图片到PDF文档(基于Spire.Cloud.PDF.SDK)

    Spire.Cloud.PDF.SDK提供了接口PdfTextApi及PdfImagesApi用于添加文本和图片到PDF文档,添加文本时,可格式化文本样式,包括文本字体类型.字号.字体样式.文本颜色. ...

  2. C# 加密、解密PDF文档(基于Spire.Cloud.SDK for .NET)

    Spire.Cloud.SDK for .NET提供了接口PdfSecurityApi可用于加密.解密PDF文档.本文将通过C#代码演示具体加密及解密方法. 使用工具: Spire.Cloud.SDK ...

  3. Java 设置、删除、获取Word文档背景(基于Spire.Cloud.SDK for Java)

    本文介绍使用Spire.Cloud.SDK for Java 提供的BackgroundApi接口来操作Word文档背景的方法,可设置背景,包括设置颜色背景setBackgroundColor().图 ...

  4. C# 设置Word文档背景(纯色/渐变/图片背景)

    Word是我们日常生活.学习和工作中必不可少的文档处理工具.精致美观的文档能给人带来阅读时视觉上的美感.在本篇文章中,将介绍如何使用组件Free Spire.Doc for .NET(社区版)给Wor ...

  5. ASP.NET实现在线浏览Word文档另一种解决方案(Word转PDF)

    ASP.NET实现在线浏览Word文档另一种解决方案(Word转PDF)      上述博文里提到的在线浏览pdf的方案不错,但word转pdf的那个dll只支持doc不支持docx,附上最新的下载链 ...

  6. C# 添加、删除、读取Word形状(基于Spire.Cloud.Word.SDK)

    本文介绍调用Spire.Cloud.Word.SDK提供的接口shapesApi来操作Word形状,包括添加形状AddShape(),添加形状时,可设置形状类型.颜色.大小.位置.倾斜.轮廓.文本环绕 ...

  7. asp.net对word文档进行修改 对于使用word文档做模板编辑比较适用

    最近做项目,需要多word文档进行编辑并导出一个新的word,在最初的word编辑中留下特定的字符串用来替换,然后在本地生成一个新的word文档,并且不修改服务器中的word文档,这样才能保证服务器中 ...

  8. C# 将Word转为PDF、XPS、Epub、RTF(基于Spire.Cloud.Word.SDK)

    本文介绍通过调用Spire.Cloud.Word.SDK提供的ConvertApi接口将Word转换为PDF.XPS.Epub.RTF以及将Docx转为Doc格式等.调用接口方法及步骤参考以下步骤: ...

  9. 打开word文档时提示“Microsoft Office Word已停止工作”

    我的电脑(Win10)有Office 2003和2013两个版本,可能由于之前超长待机等原因导致word 2003的文件(.doc)不能正常打开,没次都会提示“Microsoft Office Wor ...

随机推荐

  1. SpringBoot RESTful api

    一.REST简单介绍 REST代表Representational State Transfer,是一种URI风格,是一组架构约束条件和原则.REST风格服务调用就是解析URL请求,将请求由逻辑构建处 ...

  2. 易初大数据 2019年10月20日 linux死亡导图 王庆超

  3. HTML——基础知识点1

  4. C语言程序设计100例之(10):最大公约数

    例10        最大公约数 问题描述 有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b.若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c. 输入数据 第 ...

  5. nyoj 168-房间安排 (贪心)

    168-房间安排 内存限制:64MB 时间限制:3000ms 特判: No 通过数:33 提交数:71 难度:2 题目描述: 2010年上海世界博览会(Expo2010),是第41届世界博览会.于20 ...

  6. 【dp】 AreYouBusy

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意: 多组背包, 0类型为为至少去1样, 1为至多取1样, 2 为随意. 如果将2类型 再添加 ...

  7. gcc悄无声色将静态函数内联了

    说到内联,可能你还停在十几年前甚至二十多年前的C++教典,c++有内联关键字inline,甚至还用来与c做区分.c99开始c引入inline,gcc比c99早实现对inline支持,vc中c没有关键字 ...

  8. C# UTM坐标和WGS84坐标转换小工具

    工具根据:http://home.hiwaay.net/~taylorc/toolbox/geography/geoutm.html js代码改编 工具源码github:https://github. ...

  9. JAVA语 言 的 特 点

    Java到 底 是 一 种 什 么 样 的 语 言 呢? Java是 一 种 简 单 的 面 象 对 象 的 分 布 式 的 解 释 的 健 壮 的 安 全 的 结 构 中 立 的 可 移 植 的 性 ...

  10. 《Git的常用操作》

    Git的常用操作: git checkout -b 本地分支 #创建本地的分支—本地分支,并切换到该分支下. git branch --set-upstream-to=origin/远程分支 本地分支 ...