這篇文章主要講解了“C#怎么設置、刪除、讀取Word文檔背景”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“C#怎么設置、刪除、讀取Word文檔背景”吧!
目前成都創(chuàng)新互聯(lián)公司已為上千的企業(yè)提供了網(wǎng)站建設、域名、虛擬空間、網(wǎng)站運營、企業(yè)網(wǎng)站設計、文縣網(wǎng)站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
Spire.Cloud.Word.Sdk提供了接口SetBackgroudColor()、SetBackgroudImage()、DeleteBackground()、GetBackgroudColor()用于設置、刪除及讀取Word文檔背景。本文將以C#程序為例演示如何來調用API接口實現(xiàn)以上內容操作。
必要步驟:
步驟一:dll文件獲取及導入。通過官網(wǎng) 下載SDK文件包。

下載后,解壓文件,將Spire.Cloud.Word.Sdk.dll文件及其他三個dll添加引用至VS程序(如下圖);或者在程序中通過Nuget搜索安裝,直接導入。

步驟二:App ID及Key獲取。在 云端創(chuàng)建賬號,并在“我的應用”板塊中創(chuàng)建應用以獲得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);
//創(chuàng)建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);
//創(chuàng)建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);
//創(chuàng)建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);
//創(chuàng)建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();
}
}
}背景色讀取結果:

感謝各位的閱讀,以上就是“C#怎么設置、刪除、讀取Word文檔背景”的內容了,經過本文的學習后,相信大家對C#怎么設置、刪除、讀取Word文檔背景這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關知識點的文章,歡迎關注!
分享題目:C#怎么設置、刪除、讀取Word文檔背景
URL網(wǎng)址:http://www.chinadenli.net/article32/gpcppc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設、網(wǎng)站收錄、微信公眾號、網(wǎng)站導航、網(wǎng)頁設計公司、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)