sheet/api/mcp-api.md
58.5 KB查看源码腾讯文档 Sheet MCP 工具完整参考#
本文件包含腾讯文档 Sheet MCP 所有工具的通用 API 说明、详细调用示例、参数说明和返回值说明。
通用说明#
公共参数#
所有工具都包含以下公共参数:
file_id(string, 通常必填): 文档唯一标识符;支持file_url的工具可与file_url二选一sheet_id(string, 必填): 子表 ID(部分工具不需要或可选,详见各工具说明)
部分工具支持 file_url 与 file_id 二选一,具体以各工具参数说明为准。
响应结构#
除单个工具另有返回值说明外,API 成功时返回空对象 {},失败时会抛出对应错误信息。
工具调用示例#
1. sheet.set_cell_value#
功能说明#
设置在线表格指定单元格的值,支持文本、数字、布尔、公式等类型(SHEET)。
💡 建议:单次写入操作的请求体内容尽量不超过 1MB,超大内容请拆分为多次写入。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"cell": {
"row": 0,
"col": 0,
"value_type": "STRING",
"string_value": "Hello World"
}
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDcell(object, 必填): 单元格值参数row(int64, 必填): 行索引(0-based)col(int64, 必填): 列索引(0-based)value_type(string, 必填): 值类型,可选值:STRING、NUMBER、BOOL、FORMULAnumber_value(double, 可选): 数值,value_type为NUMBER时使用string_value(string, 可选): 字符串值,value_type为STRING时使用bool_value(bool, 可选): 布尔值,value_type为BOOL时使用formula(string, 可选): 公式,value_type为FORMULA时使用,例如"=SUM(A1:A10)"
返回值说明#
{}
2. sheet.set_range_value#
功能说明#
批量设置在线表格多个单元格的值(SHEET)。
💡 建议:单次写入操作的请求体内容尽量不超过 1MB(大约几千个单元格,视单元格内容长度而定),超大批量请拆分为多次写入。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"values": [
{
"row": 0,
"col": 0,
"value_type": "STRING",
"string_value": "Name"
},
{
"row": 0,
"col": 1,
"value_type": "STRING",
"string_value": "Score"
},
{
"row": 1,
"col": 0,
"value_type": "STRING",
"string_value": "Alice"
},
{
"row": 1,
"col": 1,
"value_type": "NUMBER",
"number_value": 95.5
}
]
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDvalues(array, 必填): 单元格值列表,每个元素与set_cell_value的cell参数结构相同
返回值说明#
{}
3. sheet.set_cell_style#
功能说明#
设置在线表格指定范围单元格的样式,包括字体、颜色、对齐等(SHEET)。同时支持三种清除场景:
- 顶层
is_clear=true:清除区域内所有样式(字体/对齐/背景/数字格式等),此时format字段被忽略。 format内字段级清除:bool字段传false、string字段传空字符串""、int32字段传0,均表示清除该单个属性。- 未传字段:保持原值不变。
调用示例#
示例 1:设置样式#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 5,
"end_col": 3,
"format": {
"bold": true,
"italic": false,
"font_size": 12,
"font_color": "FF000000",
"bg_color": "FFFFFF00",
"horizontal_align": "center",
"vertical_align": "center",
"wrap_text": true
}
}
示例 2:整体清除区域样式#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 5,
"end_col": 3,
"is_clear": true
}
示例 3:只清除背景色 + 取消加粗#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 5,
"end_col": 3,
"format": {
"bold": false,
"bg_color": ""
}
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row(int64, 必填): 起始行索引(0-based)start_col(int64, 必填): 起始列索引(0-based)end_row(int64, 必填): 结束行索引end_col(int64, 必填): 结束列索引is_clear(bool, 可选): 若为 true 则清除区域内单元格的所有样式,同时忽略format字段format(object, 可选): 样式参数对象(is_clear=true时被忽略)bold(bool, 可选): 是否粗体;传false表示清除粗体italic(bool, 可选): 是否斜体;传false表示清除斜体font_family(string, 可选): 字体名称;传""表示清除字体font_size(int32, 可选): 字号(pt);传0表示清除字号font_color(string, 可选): 字体颜色,ARGB hex,如"FF000000";传""表示清除字体颜色bg_color(string, 可选): 背景色,ARGB hex,如"FFFFFFFF";传""表示清除背景色horizontal_align(string, 可选): 水平对齐:general/left/center/right/fill/justify;传""表示清除水平对齐vertical_align(string, 可选): 垂直对齐:top/center/bottom/justify;传""表示清除垂直对齐wrap_text(bool, 可选): 是否自动换行;传false表示清除自动换行strike_through(bool, 可选): 是否删除线;传false表示清除删除线underline(string, 可选): 下划线类型:none/single/double/single_accounting/double_accounting;传""表示清除下划线number_format_pattern(string, 可选): 数字格式,如"0.00%";传""表示清除数字格式
返回值说明#
{}
4. sheet.merge_cell#
功能说明#
合并在线表格指定范围的单元格,支持全部合并、按行合并、按列合并(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 3,
"end_col": 3,
"merge_type": "all"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row(int64, 必填): 起始行索引(0-based)start_col(int64, 必填): 起始列索引(0-based)end_row(int64, 必填): 结束行索引end_col(int64, 必填): 结束列索引merge_type(string, 必填): 合并类型"all": 全部合并(默认)"columns": 按列合并"rows": 按行合并
返回值说明#
{}
5. sheet.insert_dimension#
功能说明#
在在线表格指定位置插入行或列(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"dimension_type": "row",
"index": 2,
"count": 3,
"direction": "before"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDdimension_type(string, 必填): 行列类型:"row"|"col"index(int64, 必填): 起始索引(0-based)count(int64, 必填): 插入数量direction(string, 可选): 插入方向:"before"(默认)|"after"
返回值说明#
{}
6. sheet.delete_dimension#
功能说明#
删除在线表格指定位置的行或列(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"dimension_type": "col",
"index": 3,
"count": 2
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDdimension_type(string, 必填): 行列类型:"row"|"col"index(int64, 必填): 起始索引(0-based)count(int64, 必填): 删除数量
返回值说明#
{}
7. sheet.set_freeze#
功能说明#
设置在线表格的冻结行列数,传 0 可取消冻结(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"row_count": 1,
"col_count": 2
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDrow_count(int64, 必填): 冻结行数(0 = 取消冻结行)col_count(int64, 必填): 冻结列数(0 = 取消冻结列)
返回值说明#
{}
8. sheet.set_filter#
功能说明#
为在线表格指定数据区域设置筛选(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 100,
"end_col": 5
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row(int64, 必填): 数据区域起始行(0-based)start_col(int64, 必填): 数据区域起始列(0-based)end_row(int64, 必填): 数据区域结束行end_col(int64, 必填): 数据区域结束列filter_id(string, 可选): 筛选 ID(不传则自动生成)
返回值说明#
{}
9. sheet.remove_filter#
功能说明#
移除在线表格的筛选,可按筛选 ID 精确移除或移除全部(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"filter_id": "filter_001"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDfilter_id(string, 可选): 筛选 ID(不传则移除该子表所有筛选)
返回值说明#
{}
10. sheet.set_link#
功能说明#
为在线表格指定单元格设置超链接,可指定链接 URL 和显示文本(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"row": 0,
"col": 0,
"url": "https://docs.qq.com",
"display_text": "腾讯文档"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDrow(int64, 必填): 单元格行(0-based)col(int64, 必填): 单元格列(0-based)url(string, 必填): 超链接 URLdisplay_text(string, 可选): 单元格显示文本
返回值说明#
{}
11. sheet.clear_link#
功能说明#
清除在线表格指定单元格的超链接,可按链接 ID 精确清除或清除全部超链接(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"row": 0,
"col": 0,
"link_id": "link_001"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDrow(int64, 必填): 单元格行(0-based)col(int64, 必填): 单元格列(0-based)link_id(string, 可选): 链接 ID(不传则按位置清除)
返回值说明#
{}
12. sheet.unmerge_cell#
功能说明#
取消在线表格指定区域的单元格合并(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 3,
"end_col": 3
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row(int64, 必填): 起始行索引(0-based)start_col(int64, 必填): 起始列索引(0-based)end_row(int64, 必填): 结束行索引end_col(int64, 必填): 结束列索引
返回值说明#
{}
13. sheet.clear_range_cells#
功能说明#
清除在线表格指定区域内所有单元格的内容,不影响样式(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 9,
"end_col": 4
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row(int64, 必填): 起始行索引(0-based)start_col(int64, 必填): 起始列索引(0-based)end_row(int64, 必填): 结束行索引end_col(int64, 必填): 结束列索引
返回值说明#
{}
14. sheet.clear_range_style#
功能说明#
清除在线表格指定区域内所有单元格的样式,不影响内容(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 9,
"end_col": 4
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row(int64, 必填): 起始行索引(0-based)start_col(int64, 必填): 起始列索引(0-based)end_row(int64, 必填): 结束行索引end_col(int64, 必填): 结束列索引
返回值说明#
{}
15. sheet.clear_range_all#
功能说明#
清空在线表格指定区域内所有单元格的内容和样式(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 9,
"end_col": 4
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row(int64, 必填): 起始行索引(0-based)start_col(int64, 必填): 起始列索引(0-based)end_row(int64, 必填): 结束行索引end_col(int64, 必填): 结束列索引
返回值说明#
{}
16. sheet.unset_freeze#
功能说明#
删除在线表格指定子表的所有冻结行列(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 ID
返回值说明#
{}
17. sheet.get_sheet_info#
功能说明#
获取在线表格的子表信息,包括子表 ID、名称、类型、行列数量、已用区域末行/末列、是否隐藏子表(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890"
}
参数说明#
file_id(string, 必填): 文档 ID
注意:此工具不需要
sheet_id参数,返回文档下所有子表的信息。
返回值说明#
{
"sheets": [
{
"sheet_id": "sub_sheet_001",
"sheet_name": "Sheet1",
"sheet_type": "worksheet",
"row_count": 100,
"col_count": 26,
"used_range": { "row_count": 53, "col_count": 12 },
"hidden": true
}
]
}
sheets(array): 子表信息列表sheet_id(string): 子表 IDsheet_name(string): 子表名称sheet_type(string): 子表类型:worksheet/smartsheet/smartcanvasrow_count(int32): 行数col_count(int32): 列数used_range(object, 可选): 已用区域末行/末列(1-based,空表为 0)。不下发表示引擎未算出已用区,此时应退回row_count/col_count的网格尺寸row_count(int32): 已用区域末行col_count(int32): 已用区域末列
hidden(bool, 可选): 是否隐藏子表。proto3 会省略 false,仅隐藏子表会下发该字段,缺省即可见
18. sheet.get_cell_data#
功能说明#
获取在线表格指定区域的单元格数据,支持返回 CSV 格式或结构化单元格数据(SHEET)。
⚠️ 限制:单次请求的单元格范围不得超过 20000 个(即
(end_row - start_row + 1) × (end_col - start_col + 1) ≤ 20000),超出将返回错误。如需获取更大范围的数据,请分多次请求。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 9,
"end_col": 4,
"return_csv": false
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row(int64, 必填): 起始行索引(0-based)start_col(int64, 必填): 起始列索引(0-based)end_row(int64, 必填): 结束行索引end_col(int64, 必填): 结束列索引return_csv(bool, 可选): 是否以 CSV 格式返回数据,true返回csv_data,false返回cells结构化数据(默认false)
返回值说明#
{
"csv_data": "Name,Score\nAlice,95.5\n",
"cells": [
{
"row": 0,
"col": 0,
"value_type": "STRING",
"string_value": "Name"
},
{
"row": 0,
"col": 1,
"value_type": "STRING",
"string_value": "Score"
}
]
}
csv_data(string): CSV 格式数据(return_csv=true时返回)cells(array): 结构化单元格数据(return_csv=false时返回)row(int32): 行索引(0-based)col(int32): 列索引(0-based)value_type(string): 值类型:NUMBER/STRING/BOOL/FORMULA/ERROR/TIME_STRING/RICH_STRINGnumber_value(double): 数值string_value(string): 字符串值bool_value(bool): 布尔值formula(string): 公式
19. sheet.get_merged_cells#
功能说明#
获取在线表格指定区域内与该区域相交的合并单元格信息,返回合并单元格范围列表(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 9,
"end_col": 9
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row(int64, 必填): 查询区域起始行索引(0-based)start_col(int64, 必填): 查询区域起始列索引(0-based)end_row(int64, 必填): 查询区域结束行索引end_col(int64, 必填): 查询区域结束列索引
返回值说明#
{
"merged_cells": [
"sub_sheet_001$A1:B2",
"sub_sheet_001$C3:D5"
]
}
merged_cells(array): 与查询区域相交的合并单元格范围列表,格式为"SheetID$A1:B2"(列使用字母表示,A=第0列,B=第1列,以此类推)
20. sheet.set_dimension_size#
功能说明#
设置在线表格指定行的行高或指定列的列宽,支持批量设置和清除自定义尺寸恢复默认值(SHEET)。支持两种模式:单个设置(使用 index)和批量设置(使用 start_index + end_index)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"dimensions": [
{
"dimension_type": "row",
"index": 0,
"size": 40
},
{
"dimension_type": "col",
"start_index": 2,
"end_index": 5,
"size": 120
},
{
"dimension_type": "row",
"index": 5,
"is_clear": true
}
]
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDdimensions(array, 必填): 行高/列宽参数列表,每个元素包含:dimension_type(string, 必填): 行列类型:"row"|"col"index(int64, 可选): 行或列的索引(0-based),设置单个行高/列宽时使用start_index(int64, 可选): 起始索引(0-based),批量设置行高/列宽时使用end_index(int64, 可选): 结束索引(0-based),批量设置行高/列宽时使用size(number, 可选): 行高或列宽的值(行高单位为pt,列宽单位为像素),is_clear为true时该字段将被忽略is_clear(bool, 可选): 是否清除自定义行高/列宽并恢复默认值,为true时size字段将被忽略
💡 说明:
index与start_index/end_index二选一。传index时设置单行/列;传start_index+end_index时批量设置该范围内所有行/列。
返回值说明#
{}
21. sheet.add_sheet#
功能说明#
在在线表格中添加一个新的子表,支持指定子表名称和位置(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"name": "新子表",
"index": 0,
"append_index": false
}
参数说明#
file_id(string, 必填): 文档 IDname(string, 可选): 子表名称,长度限制为 31 个字符,不传则使用默认名称index(int64, 可选): 子表位置索引(0-based),不传或append_index为true时追加到末尾append_index(bool, 可选): 是否追加到末尾,为true时index字段将被忽略
注意:此工具不需要
sheet_id参数,用于创建新的子表。
返回值说明#
{
"sheet_id": "new_sheet_001"
}
sheet_id(string): 新创建的子表 ID
22. sheet.delete_sheet#
功能说明#
删除在线表格中指定的子表(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 要删除的子表 ID
返回值说明#
{}
23. sheet.rename_sheet#
功能说明#
重命名在线表格中指定的子表(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"name": "新名称"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDname(string, 必填): 新的子表名称,长度限制为 31 个字符
返回值说明#
{}
24. sheet.insert_image#
功能说明#
在在线表格指定单元格插入一张图片,图片内容可通过 base64 或 image_id 传入(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"row_index": 0,
"col_index": 0,
"content": "iVBORw0KGgoAAAANSUhEUgAA..."
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDrow_index(int64, 必填): 目标行索引(0-based)col_index(int64, 必填): 目标列索引(0-based)content(string, 可选): 图片的 base64 内容,与image_id二选一,适合图片体积较小的场景;若图片过大导致 base64 内容超出传输限制,请改用image_id方式image_id(string, 可选): 图片的 image_id,本质是对图片信息加密后的字符串,与content二选一,适合图片体积较大的场景。获取方式:- 通过
upload_imageMCP 接口上传图片后获取 - 通过腾讯文档开放平台 OpenAPI 图片上传接口获取(需先完成 OAuth 授权流程获取
Access-Token),示例命令:
- 通过
curl --location --request POST 'https://docs.qq.com/openapi/resources/v2/images' \
--header 'Access-Token: ACCESS_TOKEN' \
--header 'Client-Id: CLIENT_ID' \
--header 'Open-Id: OPEN_ID' \
--form 'image=@"/path/to/your/image.png"'
上传成功后,取返回结果中的 imageID 字段值传入此参数
返回值说明#
{}
25. sheet.set_range_value_by_csv#
功能说明#
以 CSV 格式批量插入数据到在线表格(SHEET),指定左上角起始行列和 CSV 内容,自动解析并写入对应单元格。相比 set_range_value 需要逐个指定每个单元格的行列和类型,set_range_value_by_csv 只需提供一段 CSV 文本即可,更适合批量写入表格数据的场景。
💡 建议:单次写入请求体内容尽量不超过 1MB,超大批量请拆分为多次写入。
💡 类型自动检测:CSV 中的每个字段会自动检测类型——数字识别为
NUMBER,true/false识别为BOOL,以=开头识别为FORMULA,其余为STRING。空字段会被跳过。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"csv_data": "Name,Score,Pass\nAlice,95.5,true\nBob,82,true\nCharlie,59,false"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row(int64, 可选): 左上角起始行索引(0-based),默认为 0start_col(int64, 可选): 左上角起始列索引(0-based),默认为 0csv_data(string, 必填): CSV 格式的数据内容,每行以换行符分隔,每列以逗号分隔,支持标准 CSV 引号转义
返回值说明#
{}
26. sheet.get_sheet_object_list#
功能说明#
获取在线表格指定子表上的对象列表,包括图表(chart)、透视表(pivot_table)、筛选表(table)、浮动图片(float_image)(SHEET)。支持按对象类型、显示区域、名称模糊匹配过滤。返回每个对象的 ID、类型、名称、显示区域、数据来源区域以及类型相关的简要信息。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"object_types": ["chart", "float_image"],
"filter_by_range": true,
"start_row": 0,
"start_col": 0,
"end_row": 50,
"end_col": 10,
"name_pattern": ""
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDobject_types(array, 可选): 对象类型过滤列表,留空表示返回所有类型;元素取值为字符串:"chart"(图表)、"pivot_table"(透视表)、"table"(筛选表)、"float_image"(浮动图片)filter_by_range(bool, 可选): 是否按区域过滤对象,为true时才根据start_row/start_col/end_row/end_col过滤start_row(int64, 可选): 显示区域过滤起始行索引(0-based),需要filter_by_range为true时才生效start_col(int64, 可选): 显示区域过滤起始列索引(0-based)end_row(int64, 可选): 显示区域过滤结束行索引end_col(int64, 可选): 显示区域过滤结束列索引name_pattern(string, 可选): 对象名称模糊匹配模式,留空表示不按名称过滤
返回值说明#
{
"objects": [
{
"object_id": "chart_001",
"object_type": "chart",
"name": "销售趋势图",
"display_range": "sub_sheet_001$A1:F15",
"data_range": "sub_sheet_001$A1:B10",
"chart_type": 1
}
]
}
objects(array): 子表上的对象列表object_id(string): 对象唯一 IDobject_type(string): 对象类型:"chart"/"pivot_table"/"table"/"float_image"/"unknown"name(string): 对象名称display_range(string): 显示区域,格式如"SheetID$A1:B2"data_range(string): 数据来源区域,格式如"SheetID$A1:B2"chart_type(int32): 图表类型枚举值,仅当object_type=="chart"时有效pivot_row_group_count(int32): 透视表行分组数pivot_column_group_count(int32): 透视表列分组数pivot_value_count(int32): 透视表值字段数table_has_header(bool): 筛选表是否含表头table_column_count(int32): 筛选表列数float_image_width(int32): 浮动图片宽度float_image_height(int32): 浮动图片高度
27. sheet.move_dimension#
功能说明#
在在线表格中移动一段连续的行或列到新的位置(SHEET)。移动语义与 Apps Script moveRows/moveColumns 一致:index 表示要移动的起始行/列索引(0-based),count 表示要移动的行/列数量,to 表示移动到的目标位置索引(0-based,相对原表)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"dimension_type": "row",
"index": 0,
"count": 3,
"to": 10
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDdimension_type(string, 必填): 行列类型:"row"|"col"index(int64, 必填): 待移动的起始索引(0-based)count(int64, 必填): 待移动的行/列数量to(int64, 必填): 目标位置索引(0-based,相对原表)
返回值说明#
{}
28. sheet.update_filter#
功能说明#
更新在线表格筛选的范围和/或列筛选项(SHEET),支持 VALUE 值筛选、COLOR 背景/字体颜色筛选和 CONDITION 条件筛选。
调用示例#
同时更新范围与列条件(is_update_range=true 时 start_row / start_col / end_row / end_col 必须全部传入):
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"is_update_range": true,
"start_row": 0,
"start_col": 0,
"end_row": 100,
"end_col": 5,
"columns": [
{ "col": 0, "visible_values": ["北京", "上海"] },
{ "col": 2, "criteria_type": "VALUE", "visible_values": ["已完成"] }
]
}
保留原范围,仅更新列条件:
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"is_update_range": false,
"columns": [
{ "col": 2, "criteria_type": "CONDITION", "condition_criteria": { "criteria1": { "op": "BETWEEN", "formulas": ["10", "100"] } } }
]
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDis_update_range(bool, 可选): 默认false,保留原范围;true时以下 4 个范围字段必填start_row/start_col/end_row/end_col(int64, 条件必填): 新的数据区域,仅当is_update_range=true时生效columns(array, 可选): 省略或空数组不修改原列筛选项;每项:col(int64, 必填): 非负整数列索引(0-based,相对整个子表),必须位于筛选有效范围内;远端同时更新范围和列条件时按新范围校验criteria_type(string, 可选):VALUE(默认)、COLOR或CONDITIONvisible_values(string[], VALUE 时必填): 非空数组,保留可见的值;不在列表内的值会被隐藏color_criteria(array, COLOR 时必填): 1~64 项,每项含color(#RRGGBB或不带#的 8 位 ARGB 十六进制字符串)和可选is_cell_color(默认true筛背景色,false筛字体色)condition_criteria(object, CONDITION 时必填): 必填criteria1、可选criteria2,每个条件含op和formulas;仅当提供criteria2时允许传is_and,默认false为 OR,true为 ANDop:GT、LT、GTE、LTE、EQ、NEQ、BETWEEN、NOT_BETWEEN、CONTAINS、NOT_CONTAINS、BEGINS_WITH、ENDS_WITH,大小写不敏感;也接受>、<、>=、<=、==、!=formulas(string[]):BETWEEN/NOT_BETWEEN必须 2 项,其他操作符必须 1 项,均不得为空或仅含 ASCII 空白;前 8 种数值操作符去除首尾 ASCII 空白后,只接受有限数值字面量(如"10"、".5",不接受公式;小数点后必须有数字,"1."会被拒绝),后 4 种文本操作符保留原始文本(如"北京",不要自行添加引号,Unicode 空白不被移除)- 文本匹配:
CONTAINS/NOT_CONTAINS沿用SEARCH的通配符且忽略大小写;BEGINS_WITH/ENDS_WITH区分大小写
- 每列只能提供与
criteria_type匹配的筛选字段,不匹配字段会被拒绝 - 同一筛选范围的不同列暂不允许混用
VALUE/COLOR/CONDITION(包括历史已设条件),冲突时整次请求拒绝;单列可以切换类型。更换全范围筛选类型时,应先清除旧筛选并重建 - 未更新范围且
columns省略或为空时,请求会被拒绝 - 无筛选时,先创建筛选范围,再另行调用设置列条件;远端已有筛选可在一次调用中同时更新范围与列条件
- 本地
sheet_update_filter与此不同:is_update_range=true时只更新范围,忽略已校验的columns;需要设置列条件时请另行调用
返回值说明#
{}
29. sheet.find#
功能说明#
在表格中搜索指定文本,返回匹配的单元格位置(SHEET)。支持大小写敏感、整单元格匹配、正则表达式、搜索公式等选项;支持基于 offset / max_results 的分页。
调用示例#
{
"file_id": "sheet_1234567890",
"search_term": "张三",
"sheet_name": "Sheet1",
"match_case": false,
"match_entire_cell": false,
"use_regex": false,
"match_formulas": false,
"offset": 0,
"max_results": 50
}
参数说明#
file_id(string, 必填): 文档 IDsearch_term(string, 必填): 要搜索的文本sheet_name(string, 可选): 限定搜索的子表名称,不指定则全表搜索start_row/start_col(int64, 可选): 搜索起始行/列(0-based,不传从 0 开始)end_row/end_col(int64, 可选): 搜索结束行/列(0-based,不传到最后一行/列)offset(int64, 可选): 分页偏移量(默认 0)match_case(bool, 可选): 大小写敏感(默认false)match_entire_cell(bool, 可选): 整单元格匹配(默认false)use_regex(bool, 可选): 将搜索文本作为正则表达式(默认false)match_formulas(bool, 可选): 搜索公式内容(默认false)max_results(int64, 可选): 每页最大结果数(默认 50)
注意:此工具不需要
sheet_id参数,可通过sheet_name限定子表,未指定则全表搜索。
返回值说明#
{
"total_results": 12,
"results": [
{ "sheet_id": "sub_sheet_001", "row": 2, "col": 0, "address": "A3" }
],
"overflow": false,
"next_offset": 0
}
total_results(int64): 本次查找命中的总结果数results(array): 当前页命中单元格列表,每项含sheet_id、row/col(0-based)、address(A1 风格 1-based 地址)overflow(bool): 是否超过引擎底层 / 分页限制仍有更多未返回的结果next_offset(int64): 当overflow=true且仅因分页截断时下一页的 offset;后端原生 overflow 场景下为 0
30. sheet.get_cell_style#
功能说明#
获取在线表格指定区域单元格的样式信息(SHEET),包括背景色、字体颜色、字号、字体、数字格式。返回每个单元格的位置和样式字段,未设置的样式对应字段为空。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 5,
"end_col": 5
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row/start_col/end_row/end_col(int64, 必填): 查询区域(0-based)
返回值说明#
{
"cells": [
{
"row": 0,
"col": 0,
"background_color": "FFFFFF00",
"font_color": "FF000000",
"font_size": 12,
"font_family": "微软雅黑",
"number_format": ""
}
]
}
cells(array): 单元格样式列表,区域内每个单元格一项row/col(int32): 行/列索引(0-based)background_color(string): 背景色 ARGB hex,未设置时为空font_color(string): 字体颜色 ARGB hex,未设置时为空font_size(int32): 字号 pt,未设置时为 0font_family(string): 字体名称,未设置时为空number_format(string): 数字格式,未设置时为空
31. sheet.move_sheet#
功能说明#
移动在线表格中子表的顺序,按源位置和目标位置(均为 0-based 索引)调整子表排列(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"src_index": 2,
"dest_index": 0
}
参数说明#
file_id(string, 必填): 文档 IDsrc_index(int64, 必填): 源位置子表索引(0-based)dest_index(int64, 必填): 目标位置子表索引(0-based)
注意:此工具不需要
sheet_id参数,按子表索引位置定位。
返回值说明#
{}
32. sheet.set_border#
功能说明#
设置在线表格指定区域单元格的边框样式(SHEET),支持设置上下左右及内部横竖边框,可指定边框颜色和线型。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 5,
"end_col": 5,
"border_positions": [0, 1, 2, 3],
"border_style": 1,
"border_color": "FF0000"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row/start_col/end_row/end_col(int64, 必填): 区域索引(0-based)border_positions(int[], 必填): 要设置的边框位置列表,至少一个;取值:0= 上边框(TOP)1= 下边框(BOTTOM)2= 左边框(LEFT)3= 右边框(RIGHT)4= 内部竖线(INNER_VERTICAL)5= 内部横线(INNER_HORIZONTAL)
border_style(int, 可选): 边框线型,默认1(细线);取值:0= 无、1= 细线、2= 中等、3= 虚线、4= 点线、5= 粗线、6= 双线、7= 极细线
border_color(string, 可选): 边框颜色,RGB hex(不含#),如"FF0000";不传则使用默认黑色
返回值说明#
{}
33. sheet.clear_border#
功能说明#
清除在线表格指定区域单元格的边框(SHEET),支持按位置清除指定边框或清除全部边框。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 5,
"end_col": 5,
"border_positions": [0, 1]
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row/start_col/end_row/end_col(int64, 必填): 区域索引(0-based)border_positions(int[], 可选): 要清除的边框位置列表(取值同set_border.border_positions);不传则清除全部边框
返回值说明#
{}
34. sheet.sort_range#
功能说明#
对在线表格指定区域按列排序(SHEET),支持多列排序、表头识别和筛选区域内排序(仅支持单列)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 100,
"end_col": 5,
"has_header": true,
"columns": [
{ "col": 2, "order": 1 },
{ "col": 0, "order": 0 }
]
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row/start_col/end_row/end_col(int64, 必填): 排序区域(0-based)has_header(bool, 可选): 是否含表头(首行不参与排序,默认false)columns(array, 必填): 排序列列表,至少一个,多列时按顺序依次作为排序键。每项:col(int64, 必填): 列索引(0-based,相对于整个子表)order(int, 可选): 排序方向:0= 降序(默认)、1= 升序
table_id(string, 可选): 筛选表 ID。传入时表示在筛选区域内排序,仅支持单列排序
返回值说明#
{}
35. sheet.add_chart#
功能说明#
在在线表格中添加图表(SHEET),支持指定图表类型、数据范围、位置大小等参数,自动从数据范围构建图表配置。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"chart_type": "CHART_CLUSTERED_COLUMN",
"data_range": {
"start_row": 0,
"start_col": 0,
"end_row": 9,
"end_col": 1
},
"location": {
"row_index": 1,
"col_index": 4
},
"drawing_id": "chart_001",
"title": "销售趋势"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDchart_type(string, 必填): 图表类型枚举名,常用取值:- 面积图:
CHART_AREA/CHART_AREA_3D/CHART_STACKED_AREA/CHART_PERCENT_STACKED_AREA - 折线图:
CHART_LINE/CHART_LINE_3D/CHART_STACKED_LINE - 股价图:
CHART_HIGH_LOW_CLOSE_STOCK - 雷达图:
CHART_RADAR - 散点图:
CHART_SCATTER - 饼图:
CHART_PIE - 条形图:
CHART_CLUSTERED_BAR - 柱形图:
CHART_CLUSTERED_COLUMN - 气泡图:
CHART_BUBBLE - 组合图:
CHART_CUSTOM_COMBO - 其他:
CHART_REGION_MAP/CHART_TREEMAP
- 面积图:
data_range(object, 必填): 数据范围start_row/start_col/end_row/end_col(int32, 必填): 数据区域(0-based)
drawing_id(string, 必填): 图表标识ID,由调用方生成(用于后续删除/更新图表)location(object, 可选): 图表位置和大小,不传则使用默认位置row_index(int32): 锚定单元格行索引(0-based)col_index(int32): 锚定单元格列索引(0-based)horizontal_offset(int32, 可选): 单元格内水平偏移vertical_offset(int32, 可选): 单元格内垂直偏移width(int32, 可选): 图表宽度height(int32, 可选): 图表高度
use_column_as_series(bool, 可选): 列作为系列(不设则自动检测)first_row_as_header(bool, 可选): 首行作为表头/系列名(不设则自动检测)first_column_as_category(bool, 可选): 首列作为分类轴(不设则自动检测)title(string, 可选): 图表显示标题options_json(string, 可选): 创建时同步应用的 ChartOptions JSON(patch 语义);字段列表与update_chart.options_json完全一致(含title/legend/xAxis/yAxis/secondaryYAxis/series等)。组合图会根据series[].type/series[].axis决定 series 分桶到主/次坐标轴
返回值说明#
{}
36. sheet.delete_chart#
功能说明#
删除在线表格中指定的图表(SHEET)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"drawing_id": "chart_001"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDdrawing_id(string, 必填): 要删除的图表标识ID
返回值说明#
{}
37. sheet.get_charts#
功能说明#
获取在线表格指定子表下的所有图表信息(SHEET),包括图表 ID、类型、标题、位置、数据范围以及完整 ChartOptions JSON。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 ID
返回值说明#
{
"charts": [
{
"drawing_id": "chart_001",
"chart_type": "CHART_CLUSTERED_COLUMN",
"title": "销售趋势",
"location": { "row_index": 1, "col_index": 4 },
"data_range": { "start_row": 0, "start_col": 0, "end_row": 9, "end_col": 1 },
"options_json": "{\"title\":...,\"series\":...}"
}
]
}
charts(array): 图表信息列表drawing_id(string): 图表标识IDchart_type(string): 图表类型枚举名title(string): 图表标题location(object): 图表位置和大小(与add_chart.location同结构)data_range(object): 图表数据范围(与add_chart.data_range同结构)options_json(string): 图表完整 options 配置(JSON 字符串),客户端按需JSON.parse;顶层 key 包含title/legend/xAxis/yAxis/secondaryYAxis/series等
38. sheet.update_chart#
功能说明#
更新在线表格中指定图表的类型、数据范围、位置尺寸、标题等配置(SHEET),未传字段保持原值。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"drawing_id": "chart_001",
"chart_type": "CHART_LINE",
"title": "新标题",
"bool_options": {
"use_column_as_series": { "value": true }
}
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDdrawing_id(string, 必填): 图表标识IDchart_type(string, 可选): 图表类型枚举名(取值同add_chart.chart_type),不传保持原类型location(object, 可选): 位置和尺寸,结构同add_chart.locationdata_range(object, 可选): 数据源区域,结构同add_chart.data_rangebool_options(object, 可选): 布尔选项,使用BoolValue包装类型区分"未传"和"传了 false"use_column_as_series(BoolValue): 列作为系列first_row_as_header(BoolValue): 首行作为表头first_column_as_category(BoolValue): 首列作为分类轴
title(string, 可选): 图表标题options_json(string, 可选): 完整 ChartOptions JSON(高级配置)
返回值说明#
{}
39. sheet.insert_range#
功能说明#
在指定区域插入空白单元格(SHEET)。dimension_type=col 时按列插入(选中区域及其右侧单元格右移);dimension_type=row 时按行插入(选中区域及其下方单元格下移)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 2,
"end_col": 2,
"dimension_type": "row"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row/start_col/end_row/end_col(int64, 必填): 区域索引(0-based)dimension_type(string, 必填): 移动方式:"col"(右移)|"row"(下移)
返回值说明#
{}
40. sheet.delete_range#
功能说明#
在指定区域删除单元格(SHEET)。dimension_type=col 时按列删除(右侧单元格左移);dimension_type=row 时按行删除(下方单元格上移)。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"start_row": 0,
"start_col": 0,
"end_row": 2,
"end_col": 2,
"dimension_type": "row"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 子表 IDstart_row/start_col/end_row/end_col(int64, 必填): 区域索引(0-based)dimension_type(string, 必填): 移动方式:"col"(左移)|"row"(上移)
返回值说明#
{}
41. sheet.validate_file_data#
功能说明#
校验在线表格指定版本的数据是否正常(排障专用,SHEET)。内部走 GetKeyframe 并开启 enable_mutation_check,若任意一条 mutation 在回放前的校验阶段失败,则返回 is_valid=false 以及失败 mutation 的阶段、类型、详细原因。推荐 is_latest=true 直接校验最新版本。
调用示例#
{
"file_id": "sheet_1234567890",
"is_latest": true
}
参数说明#
file_id(string, 必填): 文档 IDversion(int64, 可选): 要校验的修订版本号;当is_latest=true时该字段被忽略is_latest(bool, 可选): 是否校验最新版本。true时忽略version,服务端用 meta 的最新版本号;false时使用version指定历史版本
注意:此工具不需要
sheet_id参数,校验整个文档数据。
返回值说明#
{
"is_valid": false,
"checked_version": 12345,
"ret_code": 0,
"stage": "RebuildSheet",
"failed_mutation_type": 27,
"err_msg": "stage=RebuildSheet, type=27, detail=..."
}
is_valid(bool): 是否通过校验:true=数据正常;false=存在非法 mutationchecked_version(int64): 本次实际校验的版本号ret_code(int32): C++ 侧返回的错误码;校验通过时为 0;失败时为 GetKeyframe 底层错误码stage(string): 首个校验失败所在回放阶段,可能取值:RebuildWorkbook.workbook_cmds/RebuildWorkbook.revisions/RebuildSheet/RebuildSheetWithTrim/ApplyNewRevisions;校验通过时为空failed_mutation_type(int32): 首个校验失败的 mutation 类型枚举整数值;校验通过时为 0err_msg(string): 完整错误信息(含 stage / type / detail 上下文);校验通过时为空
42. sheet.add_pivot_table#
功能说明#
在在线表格中创建透视表(SHEET)。anchor 指定透视表放置位置(左上角单元格),source_range 指定数据源区域,pivot_table_id 由调用方生成并保持唯一。create_new_sheet=true 时由引擎新建子表放置(忽略 anchor_sheet_id);create_new_sheet=false(默认)时 anchor_sheet_id 必填,anchor_row/anchor_col 默认为 0。
调用示例#
{
"file_id": "sheet_1234567890",
"pivot_table_id": "pt_001",
"name": "销售透视",
"source_sheet_id": "sub_sheet_001",
"source_range": {
"start_row": 0,
"start_col": 0,
"end_row": 100,
"end_col": 5
},
"anchor_sheet_id": "sub_sheet_002",
"anchor_row": 0,
"anchor_col": 0,
"create_new_sheet": false
}
参数说明#
file_id(string, 必填): 文档 IDpivot_table_id(string, 必填): 透视表唯一ID(由调用方生成并保持唯一)name(string, 可选): 透视表显示名称source_sheet_id(string, 必填): 数据源所在子表IDsource_range(object, 必填): 数据源区域,4 个字段均必填start_row/start_col/end_row/end_col(int64, 必填): 数据源区域(0-based)
anchor_sheet_id(string, 条件必填): 锚点(透视表左上角)所在子表ID,create_new_sheet=false时必填,true时忽略anchor_row(int64, 可选): 锚点行索引(0-based,默认 0)anchor_col(int64, 可选): 锚点列索引(0-based,默认 0)create_new_sheet(bool, 可选): 是否新建子表放置透视表,默认falsenew_sheet_id(string, 可选): 新建子表的 ID(create_new_sheet=true时使用)
注意:此工具不需要顶层
sheet_id参数,使用source_sheet_id与anchor_sheet_id分别指定数据源和锚点子表。
返回值说明#
{}
43. sheet.remove_pivot_table#
功能说明#
删除在线表格中已存在的透视表(SHEET)。通过 sheet_id 与 pivot_table_id 联合定位目标透视表,删除后其关联的 pivot cache 会被一并清理。sheet_id 必须是 worksheet 子表。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_002",
"pivot_table_id": "pt_001"
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 目标透视表所在子表ID(必须是 worksheet)pivot_table_id(string, 必填): 目标透视表ID
返回值说明#
{}
44. sheet.get_pivot_table_detail#
功能说明#
读取指定透视表的详细配置(数据源、行/列/值/筛选、锚点位置、ID 等),用于展示或回显,不会修改文档(SHEET)。pivot_table_id 与 pivot_table_name 至少传一个,id 优先。
调用示例#
{
"file_id": "sheet_1234567890",
"pivot_table_id": "pt_001"
}
参数说明#
file_id(string, 必填): 文档 IDpivot_table_id(string, 二选一): 目标透视表ID(与pivot_table_name二选一,id 优先)pivot_table_name(string, 二选一): 目标透视表显示名称
注意:此工具不需要
sheet_id参数。
返回值说明#
{
"pivot_table": {
"pivot_table_id": "pt_001",
"pivot_table_name": "销售透视",
"anchor_sheet_id": "sub_sheet_002",
"anchor_row": 0,
"anchor_col": 0,
"row_group_columns": [0],
"column_group_columns": [1],
"source_sheet_id": "sub_sheet_001",
"source_data_range": {
"sheet_id": "sub_sheet_001",
"start_row_index": 0,
"start_col_index": 0,
"end_row_index": 100,
"end_col_index": 5
},
"pivot_values": [
{ "source_data_column": 2, "summarize_function": "SUM" }
],
"filters": [
{ "source_data_column": 3, "visible_values": ["北京"] }
]
}
}
pivot_table(object): 透视表详情pivot_table_id(string): 透视表IDpivot_table_name(string): 透视表显示名称anchor_sheet_id(string): 锚点所在子表IDanchor_row/anchor_col(int32): 锚点行/列索引(0-based)row_group_columns(int32[]): 行分组的源数据列索引列表column_group_columns(int32[]): 列分组的源数据列索引列表source_sheet_id(string): 数据源所在子表IDsource_data_range(object): 数据源范围(GridRange,含sheet_id/start_row_index/start_col_index/end_row_index/end_col_index)pivot_values(array): 数据值字段列表source_data_column(int32): 源数据列索引(0-based)summarize_function(string): 聚合函数大写名(SUM/COUNT/AVERAGE/MAX/MIN/PRODUCT/COUNTNUMS/STDEV/STDEVP/VAR/VARP)
filters(array): 页字段筛选器列表source_data_column(int32): 源数据列索引(0-based)visible_values(string[]): 保留可见的值
45. sheet.update_pivot_table#
功能说明#
更新已有透视表的字段配置(行分组、列分组、数据值、筛选、计算字段,SHEET)。替换语义:每次调用整体替换字段配置,未传入的分类视为清空;推荐先调 get_pivot_table_detail 拉取当前配置后再下发。sheet_id 必须是 worksheet。
⚠️ 校验规则:
pivot_values[].summarize_function必填且不区分大小写,合法值:SUM/COUNT/COUNTA/AVERAGE/MAX/MIN/PRODUCT/COUNTNUMS/STDEV/STDEVP/VAR/VARP(COUNTA 等同于 COUNT)calculated_values[]中name与formula均不能为空
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_002",
"pivot_table_id": "pt_001",
"row_groups": [{ "source_data_column": 0 }],
"column_groups": [{ "source_data_column": 1 }],
"pivot_values": [
{ "source_data_column": 2, "summarize_function": "SUM" }
],
"filters": [
{ "source_data_column": 3, "visible_values": ["北京", "上海"] }
],
"calculated_values": [
{ "name": "毛利率", "formula": "=利润/收入" }
]
}
参数说明#
file_id(string, 必填): 文档 IDsheet_id(string, 必填): 透视表所在子表ID(必须是 worksheet)pivot_table_id(string, 必填): 目标透视表IDrow_groups(array, 可选): 行分组字段(替换语义),每项{ source_data_column: int }column_groups(array, 可选): 列分组字段(替换语义),每项{ source_data_column: int }pivot_values(array, 可选): 数据值字段(替换语义),每项:source_data_column(int32, 必填): 源数据列索引(0-based)summarize_function(string, 必填): 聚合函数名称,不区分大小写,合法值见上方校验规则
filters(array, 可选): 页字段筛选器(替换语义),每项:source_data_column(int32, 必填): 源数据列索引(0-based)visible_values(string[], 可选): 保留可见的值列表
calculated_values(array, 可选): 计算字段(替换语义),每项:name(string, 必填): 字段名formula(string, 必填): 计算公式
返回值说明#
{}
46. sheet.add_protect_range#
功能说明#
在在线表格指定普通子表(worksheet)的单个矩形区域或整张子表创建保护区域(SHEET)。创建成功会同步在区域权限服务创建默认权限记录,并返回后续更新或删除使用的 protect_range_id。
调用示例#
示例 1:保护指定区域#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"range": {
"start_row": 0,
"start_col": 0,
"end_row": 10,
"end_col": 5
}
}
示例 2:保护整张子表#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001",
"whole_sheet": true
}
参数说明#
file_id(string, 可选): 文档 ID,与file_url二选一file_url(string, 可选): 在线表格的 URL 链接,与file_id二选一sheet_id(string, 必填): 子表 ID(仅支持普通子表 worksheet)range(object, 可选): 保护区域范围,单个矩形区域;与whole_sheet二选一。未传或传false的whole_sheet时,必须传rangestart_row(int64, 必填): 起始行索引(0-based)start_col(int64, 必填): 起始列索引(0-based)end_row(int64, 必填): 结束行索引(0-based,不包含该行)end_col(int64, 必填): 结束列索引(0-based,不包含该列)
whole_sheet(bool, 可选): 是否保护整张子表;传true时不能同时传range
返回值说明#
{
"protect_range_id": "protected_range_001"
}
47. sheet.update_protect_range#
功能说明#
按 protect_range_id 修改在线表格已有保护区域的范围(SHEET)。range 为替换后的单个矩形区域,仅支持普通子表(worksheet)。
调用示例#
{
"file_id": "sheet_1234567890",
"protect_range_id": "protected_range_001",
"range": {
"start_row": 2,
"start_col": 1,
"end_row": 12,
"end_col": 6
}
}
参数说明#
file_id(string, 可选): 文档 ID,与file_url二选一file_url(string, 可选): 在线表格的 URL 链接,与file_id二选一sheet_id(string, 可选): 子表 ID;protect_range_id可唯一定位子表,传入时需与保护区域所在子表一致protect_range_id(string, 必填): 要修改的保护区域 ID,由sheet.add_protect_range返回range(object, 必填): 新保护区域范围,替换语义,单个矩形区域start_row(int64, 必填): 起始行索引(0-based)start_col(int64, 必填): 起始列索引(0-based)end_row(int64, 必填): 结束行索引(0-based,不包含该行)end_col(int64, 必填): 结束列索引(0-based,不包含该列)
返回值说明#
{}
48. sheet.delete_protect_range#
功能说明#
按 protect_range_id 删除在线表格已有保护区域(SHEET),并同步清理区域权限服务记录。仅支持普通子表(worksheet)。
调用示例#
{
"file_id": "sheet_1234567890",
"protect_range_id": "protected_range_001"
}
参数说明#
file_id(string, 可选): 文档 ID,与file_url二选一file_url(string, 可选): 在线表格的 URL 链接,与file_id二选一sheet_id(string, 可选): 子表 ID;protect_range_id可唯一定位子表,传入时需与保护区域所在子表一致protect_range_id(string, 必填): 要删除的保护区域 ID
返回值说明#
{}
49. sheet.get_protect_ranges#
功能说明#
获取在线表格指定普通子表(worksheet)的所有保护区域(SHEET),返回每个保护区域的 protect_range_id 与 range。整张子表保护区域也会以 range 形式返回。
调用示例#
{
"file_id": "sheet_1234567890",
"sheet_id": "sub_sheet_001"
}
参数说明#
file_id(string, 可选): 文档 ID,与file_url二选一file_url(string, 可选): 在线表格的 URL 链接,与file_id二选一sheet_id(string, 必填): 子表 ID(仅支持普通子表 worksheet)
返回值说明#
{
"ranges": [
{
"protect_range_id": "protected_range_001",
"range": {
"start_row": 0,
"start_col": 0,
"end_row": 10,
"end_col": 5
}
}
]
}文件内容是平台检查时读出的文本,只供查看。平台不会运行包里的任何脚本或程序。

