企业内部开发 服务端API 文档 编辑文档 编辑文档内容
编辑文档内容
最后更新:2022/12/10
可联系渠道经理采购或代理智慧硬件接口已支持设备 联系渠道经理
编辑文档内容
最后更新:2022/12/10

目录

  • 编辑文档内容
  • 参数详细说明
  •       UpdateRequest
  •       Range
  •       Location
  •       ReplaceText
  •       InsertText
  •       DeleteContent
  •       InsertImage
  •       InsertPageBreak
  •       InsertTable
  •       InsertParagraph
  •       TextProperty
  •       UpdateTextProperty
  • 编辑文档内容

    该接口可以对一个在线文档批量执行多个更新操作。

    注意:

    1. 批量更新请求,若其中有一个操作报错则全部更新操作不生效。
    2. 单次批量更新操作数量 <= 30。

     

    请求方式:POST(HTTPS
    请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/document/batch_update?access_token=ACCESS_TOKEN

    请求包体

    {
    	"docid": "DOCID",
    	"verison": 10,
    	"requests": [
    		{
    			"insert_text": {
    				"text": "text content",
    				"location": {
    					"index": 10
    				}
    			}
    		},
    		{
    			"insert_table": {
    				"rows": 2,
    				"cols": 2,
    				"location": {
    					"index": 10
    				}
    			}
    		}
    	]
    }

    参数说明

    参数类型是否必须说明
    docidstring文档的docid
    versionuint32操作的文档版本, 该参数可以通过获取文档内容接口获得。操作后文档版本将更新一版。要更新的文档版本与最新文档版本相差不能超过100个。
    requestsobject[]更新操作列表,详见 UpdateRequest

    权限说明

    • 自建应用需配置到“可调用应用”列表中的应用secret所获取的accesstoken来调用(accesstoken如何获取?
    • 第三方应用需具有“文档”权限
    • 代开发自建应用需具有“文档”权限

    返回示例

    {
    	"errcode": 0,
    	"errmsg": "ok"
    }

    参数说明

    参数类型说明
    errcodeint32错误码
    errmsgstring错误码说明

    参数详细说明

    由于请求参数比较复杂,在本节分Object分别说明

    UpdateRequest

    更新文档的操作,每个UpdateRequest的Object中能同时填一个字段,填入多个的只会有一个生效
    示例

    {
    	"replace_text": {
    		//替换指定位置文本
    		...
    	},
    	"delete_content": {
    		//删除指定未知内容
    		...
    	}
    	...
    }

    字段说明

    字段类型说明
    replace_textobject(ReplaceText)替换指定位置文本内容
    insert_textobject(InsertText)在指定位置插入文本内容
    delete_contentobject(DeleteContent)删除指定位置内容
    insert_imageobject(InsertImage在指定位置插入图片
    insert_page_breakobject(InsertPageBreak)在指定位置插入分页符
    insert_tableobject(InsertTable)在指定位置插入表格
    insert_paragraphobject(InsertParagraph)在指定位置插入段落
    update_text_propertyobject(UpdateTextProperty)更新指定位置文本属性

    Range

    表示从start_index开始的一段范围
    示例

    {
    	"start_index": 10,
    	"length": 5
    }

    字段说明

    字段类型说明
    start_indexuint32起始位置,从0开始
    lengthuint32长度

    Location

    标准文档中的一个位置
    示例

    {
    	"index": 10
    }

    字段说明

    字段类型说明
    indexuint32位置

    ReplaceText

    示例

    {
    	"text": "hello world",
    	"ranges": [
    			{
    				"start_index": 10,
    				"length": 5
    			}
    	]
    }

    字段说明

    字段类型说明
    textstring要替换的文本
    rangesobject[](Range)要替换的文档范围,可同时替换多个位置的文本, rangs个数不超过10。

    InsertText

    插入文本
    示例

    {
    	"text": "hello world",
    	"location": {
    		"index": 10
    	}
    }

    字段说明

    字段类型说明
    textstring要插入的文本
    locationobject(Location)插入的位置

    DeleteContent

    删除指定位置内容
    示例

    {
    	"range": {
    		...
    	}
    }

    字段说明

    字段类型说明
    rangeobject(Range)要删除的范围

    InsertImage

    插入图片
    示例

    {
    	"image_id": "https://https://wework.qpic.cn/wwpic/xxxxxx",
    	"location": {
    		...
    	}
    }

    字段说明

    字段类型说明
    image_idstring图片url,通过上传图片接口获得
    locationobject(Location)插入的位置
    widthuint32图片的宽,单位是像素(px), 不传默认为图片原始宽度
    heightuint32图片的高, 单位是像素(px),不传默认为图片原始高度

    InsertPageBreak

    插入分页符
    示例

    {
    	"location": {
    		...
    	}
    }

    字段说明

    字段类型说明
    locationobject(Location)插入的位置

    InsertTable

    在指定位置插入表格,表格大小限制:

    • 行数<=100
    • 列数<=60
    • 单元格总数<=1000

    示例

    {
    	"rows": 3,
    	"cols": 3,
    	"location": {
    		...
    	}
    }

    字段说明

    字段类型说明
    rowsuint32表格行数
    colsuint32表格列数
    locationobject(Location)插入的位置

    InsertParagraph

    在指定位置插入段落
    示例

    {
    	"location": {
    		...
    	}
    }

    字段说明

    字段类型说明
    locationobject(Location)插入的位置

    TextProperty

    文本属性
    示例

    {
    	"bold": true,
    	"color": "000000",
    	"background_color": "0000FF"
    }

    字段说明

    字段类型说明
    blodbool是否加粗
    colorstring文字颜色,十六进制RRGGBB格式
    background_colorstring文字的背景颜色,十六进制RRGGBB 格式

    UpdateTextProperty

    更新指定范围的文本属性
    示例

    {
    	"text_property": {
    		...
    	},
    	"ranges": [
    		...
    	]
    }

    字段说明

    字段类型说明
    text_propertyobject(TextProperty)文本属性
    rangesobject[](Range)更新文本属性的范围,ranges个数不超过10

    上一篇
    读取收集表答案
    下一篇
    编辑表格内容