轉(zhuǎn)帖|使用教程|編輯:李顯亮|2020-05-14 10:33:12.353|閱讀 252 次
概述:Spire.Cloud是一款幫助WEB網(wǎng)站或WEB應(yīng)用系統(tǒng)輕松實(shí)現(xiàn)打開(kāi)、編輯、保存和打印Office的軟件,是目前把Office應(yīng)用到WEB平臺(tái)上的最全面的解決方案。 本文將講解如何使用Spire.Cloud.Word 添加、修改、刪除Word段落。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
你在尋找一款既能在線編輯office文件,又能實(shí)現(xiàn)與web應(yīng)用程序?qū)拥能浖幔亢们桑{(lán)公司最新推出Spire.Cloud,搭載了基于云端的Office在線編輯器和WEB API開(kāi)發(fā)接口,既能安全穩(wěn)定地實(shí)現(xiàn)WEB網(wǎng)頁(yè)端在線查看、編輯Office文檔;又能在服務(wù)器端通過(guò)代碼調(diào)用接口簡(jiǎn)單高效地實(shí)現(xiàn)讀寫Office文檔內(nèi)容。
Spire.Cloud.Word提供了ParagraphsApi接口用于操作Word中的段落,包括添加、修改、刪除段落,以及對(duì)獲取段落中的子對(duì)象、設(shè)置段落格式等。本文將介紹如何添加、修改和刪除段落。
Spire.Cloud提供了四種語(yǔ)言的SDK(包括.NET、Java、python、PHP),你可以點(diǎn)擊下載Spire.Cloud Web SDK。
步驟1:dll文件獲取及引用。下載獲取Spire.Cloud.Word.SDK package,并將Spire.Cloud.Word.Sdk.dll及其依賴項(xiàng)的dll添加引用至程序(如下圖)
步驟2:ID及Key獲取。在冰藍(lán)云網(wǎng)頁(yè)注冊(cè)賬號(hào)并登陸,在“我的應(yīng)用”板塊創(chuàng)建應(yīng)用程序,獲得 App ID 及 App Key。
步驟3:上傳Word文檔至冰藍(lán)云官網(wǎng)的“文檔管理”版塊。為了便于文檔管理,您也可以先創(chuàng)建文件夾“input”和“output”,然后將需要編輯的Word文檔上傳至input文件夾,output文件夾用于存放生成的文檔。本教程將示例文檔上傳到了input文件夾下。
步驟4:在.NET程序中編寫代碼操作input文件夾下的文檔。
具體代碼操作方法,請(qǐng)參考以下內(nèi)容。
示例1:添加段落
using System; using Spire.Cloud.Word.Sdk.Api; using Spire.Cloud.Word.Sdk.Client; namespace AddParagraph { class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置App ID和App Key Configuration configuration = new Configuration(appId, appKey); //初始化ParagraphsApi對(duì)象 ParagraphsApi paragraphsApi = new ParagraphsApi(configuration); //現(xiàn)有文檔名稱 string fileName = "示例文檔.docx"; //選擇需要插入段落的章節(jié)(section) string nodePath = "sections/0"; //存放現(xiàn)有文檔的文件夾,如果沒(méi)有文件夾則為null string folder = "input"; //使用冰藍(lán)云配置的2G空間存貯文檔,可設(shè)置為null string storage = null; //插入段落的位置 int indexOfParagraph = 2; //文檔的打開(kāi)密碼 string password = null; //添加段落的文字 string text = "這是新加的段落"; //設(shè)置生成文檔的路徑及名稱 string destFilePath = "output/添加段落.docx"; //通過(guò)AddParagraph方法添加段落 paragraphsApi.AddParagraph(fileName, nodePath, folder, storage, indexOfParagraph, password, text, destFilePath); } } }
示例2:修改段落
using System; using Spire.Cloud.Word.Sdk.Api; using Spire.Cloud.Word.Sdk.Client; namespace UpdateParagraph { class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置App ID和App Key Configuration configuration = new Configuration(appId, appKey); //初始化ParagraphsApi對(duì)象 ParagraphsApi paragraphsApi = new ParagraphsApi(configuration); //現(xiàn)有文檔名稱 string fileName = "示例文檔.docx"; //選擇需要插入段落的章節(jié)(section) string nodePath = "sections/0"; //要修改段落的索引 int index = 2; string text = "高質(zhì)量的文檔轉(zhuǎn)換功能"; //存放現(xiàn)有文檔的文件夾,如果沒(méi)有文件夾則為null string folder = "input"; //使用冰藍(lán)云配置的2G空間存貯文檔,可設(shè)置為null string storage = null; //文檔的打開(kāi)密碼 string password = null; //設(shè)置生成文檔的路徑及名稱 string destFilePath = "output/修改段落.docx"; //通過(guò)UpdateParagraphText方法修改指定段落的文本 paragraphsApi.UpdateParagraphText(fileName, nodePath, index, text, folder, storage, password, destFilePath); } } }
示例3:刪除段落
using System; using Spire.Cloud.Word.Sdk.Api; using Spire.Cloud.Word.Sdk.Client; namespace DeleteParagraph { class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置App ID和App Key Configuration configuration = new Configuration(appId, appKey); //初始化ParagraphsApi對(duì)象 ParagraphsApi paragraphsApi = new ParagraphsApi(configuration); //現(xiàn)有文檔名稱 string fileName = "示例文檔.docx"; //選擇需要插入段落的章節(jié)(section) string nodePath = "sections/0"; //要?jiǎng)h除段落的索引 int index = 2; //存放現(xiàn)有文檔的文件夾,如果沒(méi)有文件夾則為null string folder = "input"; //使用冰藍(lán)云配置的2G空間存貯文檔,可設(shè)置為null string storage = null; //文檔的打開(kāi)密碼 string password = null; //設(shè)置生成文檔的路徑及名稱 string destFilePath = "output/刪除段落.docx"; //通過(guò)DeleteParagraph方法刪除指定段落 paragraphsApi.DeleteParagraph(fileName, nodePath, index, folder, storage, password, destFilePath); } } }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn