Spire.Cloud.Word.Sdk提供了接口SetBackgroudColor()、SetBackgroudImage()、DeleteBackground()、GetBackgroudColor()用于设置、删除及读取Word文档背景。本文将以C#程序为例演示如何来调用API接口实现以上内容操作。
dll文件下载及导入:
步骤一: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(255, 255, 205); //设置文档密码,如果没有密码,则设置为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(); } } }
(本文完)
相关推荐
import spire.cloud.word.sdk.client.*; import spire.cloud.word.sdk.client.api.ImagesApi; import java.io.File; public class AddImage { static String appId = "App ID"; static String appKey = "App Key...
Spire.Cloud 在线编辑器是一款基于网页的 Office 文件编辑工具,支持在网页中打开、编辑、打印 Word、Excel、PPT 文件,支持将文档保存到私有云盘。支持 IE、Chrome、FireFox、搜狗、遨游、360 等常见浏览器。Spire....
如标题所示,Spire.Doc支持获取Word文档中段落(Paragraph)和文本范围(TextRange)的样式,例如标题(Title)、标题1(Heading 1)、副标题(Subtitle)等。当然,我们也可以根据标题样式获取对应的文本。在此基础...
此工具包里面包含了Spire.Cloud.Word的Python源码以及Api Demo,可参考demo用来操作Word文档。
包含四个dll文件:Spire.Common.dll(版本1.2.792.14040);Spire.Liscense.dll(版本1.3.6.40);Spire.Doc.dll(版本6.8.16.4040);Spire.Pdf(版本4.8.15.2040) 使用时引用将四个文件都引用到项目。 **亲测Word...
此工具包里面包含了Spire.Cloud.PowerPoint的PHP源码以及Api Demo,可参考demo用来操作PPT文档。
此工具包里面包含了Spire.Cloud.Excel的PHP源码以及Api Demo,可参考demo用来操作Excel文档。
.Net版 Spire.Pdf v5.12.15.2040 去除水印,可超10页,用例代码。 包含Spire.Pdf.dll、Spire.License.dll。
C#-Spire.Doc-Spire.-Spire. .Net 8.10 去水印,内含Spire.Doc.dll,Spire..dll,绝对可以用,自己引用相应依赖,否则报错或有的字体无法转换。
Free Spire.Doc for .NET是一款免费的专门对 Word 文档进行操作的 .NET类库。适用于商业或个人用途。这款控件的主要功能在于帮助开发人员轻松快捷高效地创建、编辑和转换 Microsoft Word 文档。作为一款独立的 Word ...
Free Spire.Office for .NET 涵盖 E-iceblue 所有 .NET Office 免费组件的集合,它包括的免费产品有:Free Spire.Doc,Free Spire.DocViewer,Free Spire XLS,Free Spire.Presentation,Free Spire.PDF,Free Spire...
1.2 文档操作:超链接添加、编辑、删除、读取;文档修订、合并、拆分、复制、比较、加密;分页符、分节符;添加、删除、读取内容开年;OLE对象插入、读取;数学公式;页眉页脚;页面背景;页面方向、大小设置;水印...
Spire.PDF api帮助文档 和 Spire.DOC api 帮助文档
Spire.Doc for Java 能执行多种 Word 文档处理任务,,包括生成、读取、转换和打印 Word 文档,插入图片,添加页眉和页脚,创建表格,添加表单域和邮件合并域,添加书签,添加文本和图片水印等。
该资源包含了可调用接口创建、编辑、保存、打印PDF文档的SDK以及Web API示例。具体使用方法,可参考资源包内的TXT文档说明。
Spire.Doc for Java 能执行多种 Word 文档处理任务,,包括生成、读取、转换和打印 Word 文档,插入图片,添加页眉和页脚,创建表格,添加表单域和邮件合并域,添加书签,添加文本和图片水印等。
spire.doc API文档 spire.doc API文档spire.doc API文档
Spire.Cloud.SDK for .NET提供了接口PdfSecurityApi可用于加密、解密PDF文档。本文将通过C#代码演示具体加密及解密方法。 使用工具: Spire.Cloud.SDK for .NET Visual Studio 必要步骤: 步骤一: dll文件获取及...
该文件是对 Spire.Doc.dll DLL文件的简介 运行环境:未知 软件语言:简体中文 适合系统:X86系统 软件大小:4661248 B 更新时间:2011-08-14 18:56:58 文件版本:3.6.2.2 安全检测:诺顿 瑞星 卡巴 江民 金山 ...
此工具包里面包含了Spire.Cloud.PDF的Python源码以及Api Demo,可参考demo用来操作PDF文档。