# Action 参数卡片（Sheets，L2）

CRITICAL — 使用本文件前，必须先读取 `./guides/sheets-operations.md`。

本文件按 `joyspace-test.sh` 的真实调用形态提供最小参数卡片。  
字段结构、枚举、响应体请下钻 `./sheets.md`（L3）。

## 通用约定

-   示例默认使用 CLI 风格字段：`page_id`、`worksheet_id`、`row_from`、`row_to`、`col_from`、`col_to`
-   `sheets.*` 参数统一在顶层展开，禁止使用 `extra_data` 包裹层
-   行列索引统一从 `0` 开始

## 工作表管理

### sheets.getEtWorksheets

-   必填：`page_id`

```json
{ "action": "sheets.getEtWorksheets", "page_id": "<page_id>" }
```

### sheets.createEtWorksheets

-   必填：`page_id`、`name`
-   常用：`position.end`

```json
{
    "action": "sheets.createEtWorksheets",
    "page_id": "<page_id>",
    "name": "0401CLI Worksheet",
    "position": { "end": true }
}
```

### sheets.updateEtWorksheets

-   必填：`page_id`、`worksheet_id`
-   常用：`name`

```json
{
    "action": "sheets.updateEtWorksheets",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "name": "0401CLI Worksheet Updated"
}
```

### sheets.deleteEtWorksheets

-   必填：`page_id`、`worksheet_id`

```json
{ "action": "sheets.deleteEtWorksheets", "page_id": "<page_id>", "worksheet_id": "<worksheet_id>" }
```

### sheets.copyEtWorksheets

-   必填：`page_id`、`worksheet_id`
-   常用：`copyFirstSheet`

```json
{
    "action": "sheets.copyEtWorksheets",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "copyFirstSheet": true
}
```

## 数据读写

### sheets.getEtRangeData

-   必填：`page_id`、`worksheet_id`、`row_from`、`row_to`、`col_from`、`col_to`
-   单次最大返回 25 行数据（`row_to - row_from + 1 <= 25`）
-   超过 25 行时，必须按行号递增分批获取（例如 `0-24`、`25-49`、`50-74`）

```json
{
    "action": "sheets.getEtRangeData",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "row_from": 0,
    "row_to": 5,
    "col_from": 0,
    "col_to": 3
}
```

### sheets.findEtRangeData

-   必填：`page_id`、`worksheet_id`、`filter`、`range`

```json
{
    "action": "sheets.findEtRangeData",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "filter": { "search": [{ "col": 4, "value": ["<keyword>"] }] },
    "range": { "rowFrom": 1, "rowTo": 100, "colFrom": 0, "colTo": 5 },
    "showTotal": true
}
```

### sheets.createEtRows

-   必填：`page_id`、`worksheet_id`、`rangeData`
-   每条 rangeData 必须包含 `rowFrom`、`rowTo`、`colFrom`、`colTo` 和操作字段（同 updateEtRangeData 格式）
-   单次请求仅允许一种 `opType`

```json
{
    "action": "sheets.createEtRows",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "rangeData": [
        {
            "opType": "cell_operation_type_formula",
            "rowFrom": 1,
            "rowTo": 1,
            "colFrom": 0,
            "colTo": 2,
            "formula": "A1"
        },
        { "opType": "cell_operation_type_formula", "rowFrom": 2, "rowTo": 2, "colFrom": 0, "colTo": 2, "formula": "B1" }
    ]
}
```

### sheets.updateEtRangeData

-   必填：`page_id`、`worksheet_id`、`rangeData`
-   强制：单次请求仅允许一种 `opType`
-   强制：每条必须包含 `opType,rowFrom,rowTo,colFrom,colTo`
-   禁止：在顶层传 `rowFrom/rowTo/colFrom/colTo` 或 `range_values/rangeValues`

```json
{
    "action": "sheets.updateEtRangeData",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "rangeData": [
        {
            "opType": "cell_operation_type_formula",
            "rowFrom": 1,
            "rowTo": 1,
            "colFrom": 1,
            "colTo": 1,
            "formula": "=SUM(A1:B1)"
        }
    ]
}
```

### sheets.deleteEtRangeData

-   必填：`page_id`、`worksheet_id`、`rangeData`
-   常用：`shiftType`

```json
{
    "action": "sheets.deleteEtRangeData",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "rangeData": [{ "colFrom": 0, "colTo": 2, "rowFrom": 0, "rowTo": 2 }],
    "shiftType": "shift_up"
}
```

## 筛选与条件格式

### sheets.openEtFilters

-   必填：`page_id`、`worksheet_id`、`range`

```json
{
    "action": "sheets.openEtFilters",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "range": { "rowFrom": 0, "rowTo": 100, "colFrom": 0, "colTo": 8 },
    "expandFilterRange": true
}
```

### sheets.updateEtFilters

-   必填：`page_id`、`worksheet_id`、`col`、`condition`

```json
{
    "action": "sheets.updateEtFilters",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "col": 1,
    "condition": {
        "operator": "filter_operator_and",
        "param1": { "customType": "filter_custom_type_equals", "val": "进行中" }
    }
}
```

### sheets.deleteEtFilters / sheets.getEtFilters

-   必填：`page_id`、`worksheet_id`

```json
{ "action": "sheets.getEtFilters", "page_id": "<page_id>", "worksheet_id": "<worksheet_id>" }
```

### sheets.createEtCfRules

-   必填：`page_id`、`worksheet_id`、`rules`

```json
{
    "action": "sheets.createEtCfRules",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "rules": [
        {
            "cfRuleType": "cf_rule_type_value_range",
            "operator": "cf_rule_operator_greater",
            "formula1": "100",
            "priority": 1,
            "ranges": [{ "colFrom": 1, "colTo": 3, "rowFrom": 2, "rowTo": 50 }]
        }
    ]
}
```

### sheets.updateEtCfRules

-   必填：`page_id`、`worksheet_id`、`rule`

```json
{
    "action": "sheets.updateEtCfRules",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "rule": {
        "id": 140616200201872,
        "cfRuleType": "cf_rule_type_value_range",
        "operator": "cf_rule_operator_greater_equal",
        "formula1": "200",
        "ranges": [{ "colFrom": 1, "colTo": 3, "rowFrom": 2, "rowTo": 50 }]
    }
}
```

### sheets.deleteEtCfRules

-   必填：`page_id`、`worksheet_id`、`ranges`

```json
{
    "action": "sheets.deleteEtCfRules",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "ranges": [{ "colFrom": 1, "colTo": 3, "rowFrom": 2, "rowTo": 50 }]
}
```

### sheets.getEtCfRules

-   必填：`page_id`、`worksheet_id`

```json
{ "action": "sheets.getEtCfRules", "page_id": "<page_id>", "worksheet_id": "<worksheet_id>" }
```

## 数据校验

### sheets.createEtDataValidations / sheets.updateEtDataValidations

-   必填：`page_id`、`worksheet_id`、`fieldType`、`args`、`range`

```json
{
    "action": "sheets.createEtDataValidations",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "fieldType": "List",
    "args": {
        "listItems": [{ "value": "选项A" }, { "value": "选项B" }],
        "validationErrorText": "请选择有效值",
        "validationErrorTitle": "校验错误"
    },
    "range": { "colFrom": 2, "colTo": 2, "rowFrom": 2, "rowTo": 100 }
}
```

### sheets.deleteEtDataValidations

-   必填：`page_id`、`worksheet_id`、`range`

```json
{
    "action": "sheets.deleteEtDataValidations",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "range": { "rowFrom": 0, "rowTo": 2, "colFrom": 0, "colTo": 2 }
}
```

### sheets.getEtDataValidations

-   必填：`page_id`、`worksheet_id`
-   常用：`colFrom`、`colTo`、`rowFrom`、`rowTo`（顶层）

```json
{
    "action": "sheets.getEtDataValidations",
    "page_id": "<page_id>",
    "worksheet_id": "<worksheet_id>",
    "colFrom": 2,
    "colTo": 2,
    "rowFrom": 2,
    "rowTo": 100
}
```

## 附件

### sheets.queryAttachment

-   必填：`page_id`、`attachment_id`
-   `attachment_id` 从 `getEtRangeData` 返回的单元格数据中获取（图片/附件类型单元格含 `attachmentId` 字段）

```json
{
    "action": "sheets.queryAttachment",
    "page_id": "<page_id>",
    "attachment_id": "<attachment_id>"
}
```

## 超链接提取

### sheets.extractHyperlinks

-   必填：`page_id`
-   可选：`worksheet_id`（仅用于返回信息，实际读取整张 ActiveSheet）、`headless`（默认 true）
-   返回：`{status, page_id, count, links:[{row, col, address, text}]}`，row/col 为 0-based
-   背景：传统表格(pageType=18)超链接地址只存在 WPS 在线组件数据模型中，`getEtRangeData` 不返回链接地址，本 action 通过 playwright 读 WPS iframe 获取
-   依赖：可选依赖 playwright（`pip install playwright && playwright install chromium`），缺失时返回清晰错误提示

```json
{
    "action": "sheets.extractHyperlinks",
    "page_id": "<page_id>"
}
```

返回示例：

```json
{
    "status": "success",
    "page_id": "xxx",
    "count": 10,
    "links": [{ "row": 2, "col": 7, "address": "https://joyspace.jd.com/pages/xxx", "text": "报告标题" }]
}
```

> 导出 Excel 时一并写入超链接：`pipeline:sheet_export` 传 `include_links: true`。
