C # to add, delete, read Word shape (based Spire.Cloud.Word.SDK)

This article provides a call interface to operate shapesApi Spire.Cloud.Word.SDK Word shapes, comprising adding a shape AddShape (), when adding a shape, the shape type can be set, color, size, position, inclination, outline, text wraps, sequential ); delete shape DeleteShape () and reading shape attribute GetShapeProperties () and the like. Call interface methods and steps refer to the following steps:
Step one: access to and imported DLL file. Through the official website of the local download the SDK package file. (To be online in e-iceblue Chinese official website editor sector registered an account and login)

C # to add, delete, read Word shape (based Spire.Cloud.Word.SDK)

After the download, unzip the file, add the Spire.Cloud.Word.Sdk.dll and three other dll files referenced to VS program; or in the program by Nuget search download directly into all dll. dll reference results as shown below:
C # to add, delete, read Word shape (based Spire.Cloud.Word.SDK)
Step two: App ID and Key acquisition. Create an application in the "My Apps" section to obtain the App ID and App Key.
C # to add, delete, read Word shape (based Spire.Cloud.Word.SDK)
Step Three: Upload source document. In the "Document Management" section, upload the source document. Here you can build folders, documents stored in the folder. When not build folder, the source document and the resulting document directly saved in the root directory. Examples in this article, built two folders, one for storing the source document and the resulting document. (Cloud platform provides free 10,000 times the number of calls and documents 2G memory)
C # to add, delete, read Word shape (based Spire.Cloud.Word.SDK)


C # code sample
1. In addition to the shape Word

using System;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Model;

namespace AddShape
{
    class Program
    {
        static string appId = "App ID";
        static string appKey = "App Key";
        static void Main(string[] args)
        {
            //配置AppID和AppKey
            Configuration wordConfiguration = new Configuration(appId, appKey);

            //实例化ShapesApi类
            ShapesApi shapesApi = new ShapesApi(wordConfiguration);

            string name = "test.docx";//源文档
            string paragraphPath = "sections/0/paragraphs/0";//段落路径
            int indexInParagraph = 1;//添加形状的段落
            string folder = "input";//源文档所在文件夹
            string storage = null;//使用冰蓝云配置的2G空间存贮文档,可设置为null
            string password = null;//源文档密码

            //设置形状属性(包括形状类型、位置、填充颜色、旋转方向、边框宽度/颜色、文本环绕类型/方式
            ShapeFormat shapeProperties = new ShapeFormat(50, 50, ShapeFormat.ShapeTypeEnum.Star)
            {
                HorizontalOrigin = ShapeFormat.HorizontalOriginEnum.Page,
                VerticalOrigin = ShapeFormat.VerticalOriginEnum.Page,
                VerticalPosition = 40,
                HorizontalPosition = 230,
                FillColor = new Color(255, 69, 0),
                Rotation = 45,
                StrokeWeight = 2,
                StrokeColor = new Color(255, 255, 0),
                TextWrappingType = ShapeFormat.TextWrappingTypeEnum.Both,
                TextWrappingStyle = ShapeFormat.TextWrappingStyleEnum.InFrontOfText,
                ZOrder = 1
            };
            string destFilePath = "output/AddShape.docx";//结果文档路径

            //调用方法添加形状
            shapesApi.AddShape(name, paragraphPath, shapeProperties, folder, storage, indexInParagraph, password, destFilePath);
        }
    }
}

Shape add effects:
C # to add, delete, read Word shape (based Spire.Cloud.Word.SDK)

2. Delete the Word in shape

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)
        {
            //配置AppID和AppKey
            Configuration wordConfiguration = new Configuration(appId, appKey);

            //实例化ShapesApi类
            ShapesApi shapesApi = new ShapesApi(wordConfiguration);

            string name = "AddShape.docx";//源文档
            string paragraphPath = "sections/0/paragraphs/0";//段落路径
            int index = 0;//要删除形状的索引
            string folder = "output";//源文档所在文件夹
            string storage = null;//使用冰蓝云配置的2G空间存贮文档,可设置为null
            string password = null;//源文档密码

            string destFilePath = "output/DeleteShape.docx";//结果文档路径

            //调用方法删除形状
            shapesApi.DeleteShape(name, paragraphPath, index, folder, storage, password, destFilePath);
        }
    }
}

Shape deleting effects:
C # to add, delete, read Word shape (based Spire.Cloud.Word.SDK)
3. Read the Word Shape Properties

using System;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Api;

namespace GetShapeProperties
{
    class Program
    {
        static string appId = "App ID";
        static string appKey = "App Key";
        static void Main(string[] args)
        {
            //配置AppID和AppKey
            Configuration wordConfiguration = new Configuration(appId, appKey);

            //实例化ShapesApi类
            ShapesApi shapesApi = new ShapesApi(wordConfiguration);

            string name = "AddShape.docx";//源文档
            string paragraphPath = "sections/0/paragraphs/0"; 
            int index = 0;//读取的形状索引
            string folder = "output";//源文档所在文件夹
            string storage = null;//使用冰蓝云配置的2G空间存贮文档,可设置为null
            string password = null;//源文档密码

            //读取属性
            System.Console.WriteLine(shapesApi.GetShapeProperties(name, paragraphPath, index, folder, storage, password));
            System.Console.ReadLine();

        }
    }
}

Property to read the results:
C # to add, delete, read Word shape (based Spire.Cloud.Word.SDK)

(This article End)

Guess you like

Origin blog.51cto.com/eiceblue/2468150