轉帖|使用教程|編輯:李顯亮|2020-05-15 10:37:26.517|閱讀 235 次
概述:Spire.Cloud是一款幫助WEB網站或WEB應用系統輕松實現打開、編輯、保存和打印Office的軟件,是目前把Office應用到WEB平臺上的最全面的解決方案。 本文將講解如何添加、刪除 Word 形狀。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
你在尋找一款既能在線編輯office文件,又能實現與web應用程序對接的軟件嗎?好巧,冰藍公司最新推出Spire.Cloud,搭載了基于云端的Office在線編輯器和WEB API開發接口,既能安全穩定地實現WEB網頁端在線查看、編輯Office文檔;又能在服務器端通過代碼調用接口簡單高效地實現讀寫Office文檔內容。
Spire.Cloud.Word提供了ParagraphsApi接口用于操作Word中的段落,包括添加、修改、刪除段落,以及對獲取段落中的子對象、設置段落格式等。本文將介紹如何添加、修改和刪除段落。
Spire.Cloud提供了四種語言的SDK(包括.NET、Java、python、PHP),你可以點擊下載Spire.Cloud Web SDK。
步驟1:dll文件獲取及引用。下載獲取Spire.Cloud.Word.SDK package,并將Spire.Cloud.Word.Sdk.dll及其依賴項的dll添加引用至程序(如下圖)
步驟2:ID及Key獲取。在冰藍云網頁注冊賬號并登陸,在“我的應用”板塊創建應用程序,獲得 App ID 及 App Key。
步驟3:上傳Word文檔至冰藍云官網的“文檔管理”版塊。為了便于文檔管理,您也可以先創建文件夾“input”和“output”,然后將需要編輯的Word文檔上傳至input文件夾,output文件夾用于存放生成的文檔。本教程將示例文檔上傳到了input文件夾下。
步驟4:在.NET程序中編寫代碼操作input文件夾下的文檔。
具體代碼操作方法,請參考以下內容。
示例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對象 ParagraphsApi paragraphsApi = new ParagraphsApi(configuration); //現有文檔名稱 string fileName = "示例文檔.docx"; //選擇需要插入段落的章節(section) string nodePath = "sections/0"; //存放現有文檔的文件夾,如果沒有文件夾則為null string folder = "input"; //使用冰藍云配置的2G空間存貯文檔,可設置為null string storage = null; //插入段落的位置 int indexOfParagraph = 2; //文檔的打開密碼 string password = null; //添加段落的文字 string text = "這是新加的段落"; //設置生成文檔的路徑及名稱 string destFilePath = "output/添加段落.docx"; //通過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 DeleteShape { 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); //初始化ShapesApi對象 ShapesApi shapesApi = new ShapesApi(configuration); //現有文檔名稱 string fileName = "示例文檔.docx"; //段落的路徑 string paragraphPath = "sections/0/paragraphs/0"; //要刪除形狀的索引 int shapeIndex = 0; //存放現有文檔的文件夾,如果沒有文件夾則為null string folder = "input"; //使用冰藍云配置的2G空間存貯文檔,可設置為null string storage = null; //文檔的打開密碼 string password = null; //設置生成文檔的路徑及名稱 string destFilePath = "output/刪除形狀.docx"; //根據索引刪除指定形狀 shapesApi.DeleteShape(fileName, paragraphPath, shapeIndex, folder, storage, password, destFilePath); } } }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn