Shapes 接口描述

 

操作Word文档中的形状,包括获取形状,添加形状,删除和更新形状。

接口方法1:getShapes()获取文档中的形状并返回List

HTTP请求方法:GET

请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/shapes

请求参数:

参数 是否必选 类型 可选值范围 说明
name string 原文档名称
password string 原文档密码,没有则为null
folder string 存放原文档的文件夹,没有则为null
storage string 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null
paragraphPath string 包含形状的段落路径

代码示例:

  • .NET
  • Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;

namespace GetShapes
{
    class Program
    {
        static string appId = "your id";
        static string appKey = "your key";
        static string baseUrl = "https://api.e-iceblue.cn";
        static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
        static ShapesApi shapesApi = new ShapesApi(wordConfiguration);
        static void Main(string[] args)
        {
            string name = "getShapes.docx";
            string folder = "input";
            string storage = null;
            string password = null;
            string paragraphPath = null;
            var response = shapesApi.GetShapes(name, folder, storage, password, paragraphPath);
        }
    }
}

	
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ShapesApi;
import spire.cloud.word.sdk.client.model.*;
import java.util.List;

public class GetShapes {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
    static ShapesApi shapesApi = new ShapesApi(wordConfiguration);
    
    public static void main(String[] args) throws ApiException {

        String name = "getShapes.docx";
        String folder = "input";
        String storage = null;
        String password = null;
        String paragraphPath = null;
        List<ObjectInfo> response = shapesApi.getShapes(name, folder, storage, password, paragraphPath);
    }
}

接口方法2:addShapes()添加形状到指定路径

HTTP请求方法:POST

请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/shapes

请求参数:

参数 是否必选 类型 可选值范围 说明
name string 原文档名称
password string 原文档密码,没有则为null
folder string 存放原文档的文件夹,没有则为null
storage string 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null
paragraphPath string 包含形状的段落路径
indexInParagraph integer 段落中插入形状的位置
shapeFormat object { "width": 0, "height": 0, "shapeType": "Rectangle", "horizontalOrigin": "Margin", "verticalOrigin": "Margin", "verticalPosition": 0, "horizontalPosition": 0, "fillColor": { "red": 0, "green": 0, "blue": 0 }, "rotation": 0, "strokeWeight": 0, "strokeColor": { "red": 0, "green": 0, "blue": 0 }, "textWrappingType": "Both", "textWrappingStyle": "Inline", "zOrder": 0 } 形状的格式
destFilePath string 结果文档的存贮路径,如果省略该参数,则默认存到根目录

代码示例:

  • .NET
  • Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Model;

namespace AddShape
{
    class Program
    {
        static string appId = "your id";
        static string appKey = "your key";
        static string baseUrl = "https://api.e-iceblue.cn";
        static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
        static ShapesApi shapesApi = new ShapesApi(wordConfiguration);
        static void Main(string[] args)
        {
            string name = "addShape.docx";
            string paragraphPath = "Section/0/Body/0/Paragraph/0";
            int indexInParagraph = 1;
            string folder = "input";
            string storage = null;
            string password = null;
            ShapeFormat shapeFormat = new ShapeFormat(40, 40, ShapeFormat.ShapeTypeEnum.Rectangle)
            {
                HorizontalOrigin = ShapeFormat.HorizontalOriginEnum.Page,
                VerticalOrigin = ShapeFormat.VerticalOriginEnum.Page,
                VerticalPosition = 200,
                HorizontalPosition = 100,
                FillColor = new Color(100, 100, 100),
                Rotation = 45,
                StrokeWeight = 2,
                StrokeColor = new Color(125, 125, 125),
                TextWrappingType = ShapeFormat.TextWrappingTypeEnum.Both,
                TextWrappingStyle = ShapeFormat.TextWrappingStyleEnum.InFrontOfText,
                ZOrder = 1
            };
            string destFilePath = "output/addShape_output.docx";
            shapesApi.AddShape(name, paragraphPath, shapeFormat, destFilePath, folder, storage, indexInParagraph, password);
        }
    }
}

	
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ShapesApi;
import spire.cloud.word.sdk.client.model.*;

public class AddShape {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
    static ShapesApi shapesApi = new ShapesApi(wordConfiguration);

    public static void main(String[] args) throws ApiException {

        String name = "addShape.docx";
        String paragraphPath = "Section/0/Body/0/Paragraph/0";
        int indexInParagraph = 1;
        String folder = "input";
        String storage = null;
        String password = null;
        ShapeFormat shapeFormat = new ShapeFormat(40f, 40f, ShapeFormat.ShapeTypeEnum.RECTANGLE);
        shapeFormat.setHorizontalOrigin(ShapeFormat.HorizontalOriginEnum.PAGE);
        shapeFormat.setVerticalOrigin(ShapeFormat.VerticalOriginEnum.PARAGRAPH);
        shapeFormat.setVerticalPosition(50f);
        shapeFormat.setHorizontalPosition(150f);
        Color color = new Color(0, 206, 209);
        shapeFormat.setFillColor(color);
        shapeFormat.setRotation(45f);
        shapeFormat.setStrokeWeight(2f);
        Color color_2 = new Color(173, 255, 47);
        shapeFormat.setStrokeColor(color_2);
        shapeFormat.setTextWrappingType(ShapeFormat.TextWrappingTypeEnum.BOTH);
        shapeFormat.setTextWrappingStyle(ShapeFormat.TextWrappingStyleEnum.INFRONTOFTEXT);
        shapeFormat.setZOrder(1);
        ShapeFormat shapeProperties = shapeFormat;
        String destFilePath = "output/addShape_output.docx";
        shapesApi.addShape(name, paragraphPath, shapeFormat, destFilePath,folder, storage, indexInParagraph, password);
    }
}

接口方法3:deleteShape()删除指定段落中的形状

HTTP请求方法:DELETE

请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/shapes/{index}

请求参数:

参数 是否必选 类型 可选值范围 说明
name string 原文档名称
password string 原文档密码,没有则为null
folder string 存放原文档的文件夹,没有则为null
storage string 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null
paragraphPath string 包含形状的段落路径
index integer 形状的索引
destFilePath string 结果文档的存贮路径,如果省略该参数,则默认存到根目录

代码示例:

  • .NET
  • Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;

namespace DeleteShape
{
    class Program
    {
        static string appId = "your id";
        static string appKey = "your key";
        static string baseUrl = "https://api.e-iceblue.cn";
        static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
        static ShapesApi shapesApi = new ShapesApi(wordConfiguration);
        static void Main(string[] args)
        {
            string name = "deleteShape.docx";
            string paragraphPath = "Section/0/Body/0/Paragraph/0";
            int index = 0;
            string folder = "input";
            string storage = null;
            string password = null;
            string destFilePath = "output/deleteShape_output.docx";
            shapesApi.DeleteShape(name, paragraphPath, index, destFilePath, folder, storage, password);
        }
    }
}

	
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ShapesApi;

public class DeleteShape {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
    static ShapesApi shapesApi = new ShapesApi(wordConfiguration);

    public static void main(String[] args) throws ApiException {

        String name = "deleteShape.docx";
        String paragraphPath = "Section/0/Body/0/Paragraph/0";
        Integer index = 0;
        String folder = "input";
        String storage = null;
        String password = null;
        String destFilePath = "output/deleteShape_output.docx";
        shapesApi.deleteShape(name, paragraphPath, index, destFilePath, folder, storage, password);
    }
}

接口方法4:getShapeFormat()获取指定形状的格式

HTTP请求方法:GET

请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/shapes/{index}/format

请求参数:

参数 是否必选 类型 可选值范围 说明
name string 原文档名称
password string 原文档密码,没有则为null
folder string 存放原文档的文件夹,没有则为null
storage string 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null
paragraphPath string 包含形状的段落路径
index integer 形状的索引

代码示例:

  • .NET
  • Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;

namespace GetShapeFormat
{
    class Program
    {
        static string appId = "your id";
        static string appKey = "your key";
        static string baseUrl = "https://api.e-iceblue.cn";
        static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
        static ShapesApi shapesApi = new ShapesApi(wordConfiguration);
        static void Main(string[] args)
        {
            string name = "template.docx";
            string paragraphPath = "Section/0/Body/0/Paragraph/0"; ;
            int index = 3;
            string folder = "input";
            string storage = null;
            string password = null;
            var response = shapesApi.GetShapeFormat(name, paragraphPath, index, folder, storage, password);
        }
    }
}

	
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ShapesApi;
import spire.cloud.word.sdk.client.model.ShapeFormat;

public class GetShapeFormat {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
    static ShapesApi shapesApi = new ShapesApi(wordConfiguration);

    public static void main(String[] args) throws ApiException {

        String name = "template.docx";
        String paragraphPath = "Section/0/Body/0/Paragraph/0"; ;
        Integer index = 3;
        String folder = "input";
        String storage = null;
        String password = null;
        ShapeFormat response = shapesApi.getShapeFormat(name, paragraphPath, index, folder, storage, password);
    }
}

接口方法5:updateShapeFormat()更新指定形状的格式

HTTP请求方法:PUT

请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/shapes/{index}/format

请求参数:

参数 是否必选 类型 可选值范围 说明
name string 原文档名称
password string 原文档密码,没有则为null
folder string 存放原文档的文件夹,没有则为null
storage string 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null
paragraphPath string 包含形状的段落路径
index integer 形状的索引
shapeFormat object { "width": 0, "height": 0, "shapeType": "Rectangle", "horizontalOrigin": "Margin", "verticalOrigin": "Margin", "verticalPosition": 0, "horizontalPosition": 0, "fillColor": { "red": 0, "green": 0, "blue": 0 }, "rotation": 0, "strokeWeight": 0, "strokeColor": { "red": 0, "green": 0, "blue": 0 }, "textWrappingType": "Both", "textWrappingStyle": "Inline", "zOrder": 0 } 形状的格式
destFilePath string 结果文档的存贮路径,如果省略该参数,则默认存到根目录

代码示例:

  • .NET
  • Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Model;

namespace UpdateShapeFormat
{
    class Program
    {
        static string appId = "your id";
        static string appKey = "your key";
        static string baseUrl = "https://api.e-iceblue.cn";
        static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
        static ShapesApi shapesApi = new ShapesApi(wordConfiguration);
        static void Main(string[] args)
        {
            string name = "updateShapeFormat.docx";
            string paragraphPath = "Section/0/Body/0/Paragraph/0";
            int index = 0;
            string folder = "input";
            string storage = null;
            string password = null;
            ShapeFormat shapeFormat = new ShapeFormat(40, 40, ShapeFormat.ShapeTypeEnum.Rectangle)
            {
                HorizontalOrigin = ShapeFormat.HorizontalOriginEnum.Page,
                VerticalOrigin = ShapeFormat.VerticalOriginEnum.Page,
                VerticalPosition = 200,
                HorizontalPosition = 100,
                FillColor = new Color(100, 100, 100),
                Rotation = 95,
                StrokeWeight = 1,
                StrokeColor = new Color(225, 15, 15),
                TextWrappingType = ShapeFormat.TextWrappingTypeEnum.Both,
                TextWrappingStyle = ShapeFormat.TextWrappingStyleEnum.InFrontOfText,
                ZOrder = 1
            };
            string destFilePath = "output/updateShapeFormat_output.docx";
            shapesApi.UpdateShapeFormat(name, paragraphPath, index, shapeFormat, destFilePath, folder, storage, password);
        }
    }
}

	
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ShapesApi;
import spire.cloud.word.sdk.client.model.Color;
import spire.cloud.word.sdk.client.model.ShapeFormat;

public class UpdateShapeFormat {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
    static ShapesApi shapesApi = new ShapesApi(wordConfiguration);

    public static void main(String[] args) throws ApiException {

        String name = "updateShapeFormat.docx";
        String paragraphPath = "Section/0/Body/0/Paragraph/0";
        Integer index = 0;
        String folder = "input";
        String storage = null;
        String password = null;
        ShapeFormat shapeFormat = new ShapeFormat(50f, 50f, ShapeFormat.ShapeTypeEnum.OCTAGON);
        shapeFormat.setHorizontalOrigin(ShapeFormat.HorizontalOriginEnum.LEFTMARGINAREA);
        shapeFormat.setVerticalOrigin(ShapeFormat.VerticalOriginEnum.PARAGRAPH);
        shapeFormat.setVerticalPosition(80f);
        shapeFormat.setHorizontalPosition(80f);
        Color color = new Color(100, 100, 100);
        shapeFormat.setFillColor(color);
        shapeFormat.setRotation(0f);
        shapeFormat.setStrokeWeight(2f);
        Color color_2 = new Color(0, 206, 209);
        shapeFormat.setStrokeColor(color_2);
        shapeFormat.setTextWrappingType(ShapeFormat.TextWrappingTypeEnum.BOTH);
        shapeFormat.setTextWrappingStyle(ShapeFormat.TextWrappingStyleEnum.INFRONTOFTEXT);
        shapeFormat.setZOrder(1);
        ShapeFormat shapeProperties = shapeFormat;
        String destFilePath = "output/updateShapeFormat_output.docx";
        shapesApi.updateShapeFormat(name, paragraphPath, index, shapeFormat, destFilePath, folder, storage, password);
    }
}