云端Office处理工具Spire.Cloud.Word基础教程:添加、删除 Word 形状

Spire.Cloud是一款帮助WEB网站或WEB应用系统轻松实现打开、编辑、保存和打印Office的软件,是目前把Office应用到WEB平台上的最全面的解决方案。 本文将讲解如何添加、删除 Word 形状。

你在寻找一款既能在线编辑office文件,又能实现与web应用程序对接的软件吗巧,冰蓝公司最新推出Spire.Cloud,搭载了基于云端的Office在线编辑器和WEBAPI开发接口,既能安全稳定地实现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文件夹下。

云端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 形状

示例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);        }    }}


是E-iceblue官方友好合作伙伴,如果您对Spire.Cloud感兴趣或需要临时License,可以联系在线客服了解具体授权价格和使用机制。

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

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

相关推荐

发表回复

登录后才能评论