新聞中心
這篇文章主要講解了“C#怎么設(shè)置、刪除、讀取Word文檔背景”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“C#怎么設(shè)置、刪除、讀取Word文檔背景”吧!
目前成都創(chuàng)新互聯(lián)公司已為上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、網(wǎng)站運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、文縣網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
Spire.Cloud.Word.Sdk提供了接口SetBackgroudColor()、SetBackgroudImage()、DeleteBackground()、GetBackgroudColor()用于設(shè)置、刪除及讀取Word文檔背景。本文將以C#程序?yàn)槔菔救绾蝸碚{(diào)用API接口實(shí)現(xiàn)以上內(nèi)容操作。
必要步驟:
步驟一:dll文件獲取及導(dǎo)入。通過官網(wǎng) 下載SDK文件包。
下載后,解壓文件,將Spire.Cloud.Word.Sdk.dll文件及其他三個(gè)dll添加引用至VS程序(如下圖);或者在程序中通過Nuget搜索安裝,直接導(dǎo)入。
步驟二:App ID及Key獲取。在 云端創(chuàng)建賬號(hào),并在“我的應(yīng)用”板塊中創(chuàng)建應(yīng)用以獲得App ID及App Key。
步驟三:源文檔上傳。在“文檔管理”板塊,上傳源文檔。這里如果想方便文檔管理,可以新建文件夾,將源文檔及結(jié)果文檔分別保存至相應(yīng)的文件夾下。不建文件夾時(shí),源文檔及結(jié)果文檔直接保存在根目錄。本文示例中,建了兩個(gè)文件夾,分別用于存放源文檔及結(jié)果文檔。
【示例1】設(shè)置背景顏色
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) { //配置賬號(hào)信息 Configuration wordConfiguration = new Configuration(appId, appKey); //創(chuàng)建BackgroundApi實(shí)例 BackgroundApi backgroundApi = new BackgroundApi(wordConfiguration); //源文檔 var fileName = "testfile.docx"; string name = fileName; //源文檔所在文件夾,若沒有文件夾則設(shè)置為null string folder = "input"; //設(shè)置背景顏色RGB值 Color color = new Color(255, 255, 205); //設(shè)置文檔密碼,如果沒有密碼,則設(shè)置為null string password = null; //使用冰藍(lán)云配置的2G空間存貯文檔,可設(shè)置為null string storage = null; //設(shè)置生成文檔的路徑及文檔名稱 string destFilePath = "output/BackgroundColor.docx"; //調(diào)用方法設(shè)置背景顏色 backgroundApi.SetBackgroudColor(name,color, folder, storage, password, destFilePath); } } }
背景顏色設(shè)置結(jié)果:
【示例2】設(shè)置背景圖片
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) { //配置賬號(hào)信息 Configuration wordConfiguration = new Configuration(appId, appKey); //創(chuàng)建BackgroundApi實(shí)例 BackgroundApi backgroundApi = new BackgroundApi(wordConfiguration); //源文檔及圖片 var fileName = "testfile.docx"; var imageName = "ss.png"; string name = fileName; //源文檔所在文件夾,若沒有文件夾則設(shè)置為null string folder = "input"; string imagePath = "input" + "/"+ imageName; //設(shè)置文檔密碼,如果沒有密碼,則設(shè)置為null string password = null; //使用冰藍(lán)云配置的2G空間存貯文檔,可設(shè)置為null string storage = null; //設(shè)置生成文檔的路徑及文檔名稱 string destFilePath = "output/BackgroundImg.docx"; //調(diào)用方法設(shè)置背景 backgroundApi.SetBackgroudImage(name, imagePath, folder, storage, password, destFilePath); } } }
背景圖片設(shè)置效果:
【示例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) { //配置賬號(hào)信息 Configuration wordConfiguration = new Configuration(appId, appKey); //創(chuàng)建BackgroundApi實(shí)例 BackgroundApi backgroundApi = new BackgroundApi(wordConfiguration); //源文檔 var fileName = "BackgroundImg.docx"; string name = fileName; //源文檔所在文件夾,若沒有文件夾則設(shè)置為null string folder = "output"; //設(shè)置文檔密碼,如果沒有密碼,則設(shè)置為null string password = null; //使用冰藍(lán)云配置的2G空間存貯文檔,可設(shè)置為null string storage = null; //設(shè)置生成文檔的路徑及文檔名稱 string destFilePath = "output/DeleteBackground.docx"; //調(diào)用方法刪除文檔中背景 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) { //配置賬號(hào)信息 Configuration wordConfiguration = new Configuration(appId, appKey); //創(chuàng)建BackgroundApi實(shí)例 BackgroundApi backgroundApi = new BackgroundApi(wordConfiguration); //源文檔 var fileName = "BackgroundColor.docx"; string name = fileName; //源文檔密碼,若無密碼可設(shè)置為null string password = null; //源文檔所在文件夾,若沒有文件夾則設(shè)置為null string folder = "output"; //使用冰藍(lán)云配置的2G空間存貯文檔,可設(shè)置為null string storage = null; //獲取文檔背景色 System.Console.WriteLine(backgroundApi.GetBackgroudColor(name, password, folder, storage)); System.Console.ReadLine(); } } }
背景色讀取結(jié)果:
感謝各位的閱讀,以上就是“C#怎么設(shè)置、刪除、讀取Word文檔背景”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)C#怎么設(shè)置、刪除、讀取Word文檔背景這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
網(wǎng)站名稱:C#怎么設(shè)置、刪除、讀取Word文檔背景
標(biāo)題鏈接:http://www.ef60e0e.cn/article/gpcppc.html