云端Office处理工具Spire.Cloud.Word基础教程:添加、修改、删除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。

云端Office处理工具Spire.Cloud.Word基础教程:添加 Word 水印添加、修改、删除Word段落

步骤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);        }    }}

云端Office处理工具Spire.Cloud.Word基础教程:添加 Word 水印添加、修改、删除Word段落

示例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对象            ParagraphsApi paragraphsApi = new ParagraphsApi(configuration);            //现有文档名称            string fileName = "示例文档.docx";            //选择需要插入段落的章节(section)            string nodePath = "sections/0";            //要修改段落的索引            int index = 2;            string text = "高质量的文档转换功能";            //存放现有文档的文件夹,如果没有文件夹则为null            string folder = "input";            //使用冰蓝云配置的2G空间存贮文档,可设置为null            string storage = null;            //文档的打开密码            string password = null;            //设置生成文档的路径及名称            string destFilePath = "output/修改段落.docx";            //通过UpdateParagraphText方法修改指定段落的文本            paragraphsApi.UpdateParagraphText(fileName, nodePath, index, text, folder, storage, password, destFilePath);        }    }}

云端Office处理工具Spire.Cloud.Word基础教程:添加 Word 水印添加、修改、删除Word段落

示例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对象            ParagraphsApi paragraphsApi = new ParagraphsApi(configuration);            //现有文档名称            string fileName = "示例文档.docx";            //选择需要插入段落的章节(section)            string nodePath = "sections/0";            //要删除段落的索引            int index = 2;            //存放现有文档的文件夹,如果没有文件夹则为null            string folder = "input";            //使用冰蓝云配置的2G空间存贮文档,可设置为null            string storage = null;            //文档的打开密码            string password = null;            //设置生成文档的路径及名称            string destFilePath = "output/删除段落.docx";            //通过DeleteParagraph方法删除指定段落            paragraphsApi.DeleteParagraph(fileName, nodePath, index, folder, storage, password, destFilePath);        }    }}

云端Office处理工具Spire.Cloud.Word基础教程:添加 Word 水印添加、修改、删除Word段落
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年4月11日
下一篇 2020年4月11日

相关推荐

发表回复

登录后才能评论