# Replace cells

Find data that matches specified conditions in a certain range of the sheet, replace the values, and return the location of the successfully replaced cell. You can replace up to 5,000 cells at a time. If the number of matching cells exceeds the limit, narrow the range before the action. The range, find, and replacement fields are required in the request body.

## Request

Facts | &nbsp;
---|---
HTTP URL | https://open.feishu.cn/open-apis/sheets/v3/spreadsheets/:spreadsheet_token/sheets/:sheet_id/replace
HTTP Method | POST
Rate Limit | [20 per minute](https://open.feishu.cn/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
Supported app types | Custom App、Store App
Required scopes<br>**To use this API, you must have at least 1 of the listed scopes.**<br>Enable any scope from the list | View, comment, edit, and manage all files in My Space(drive:drive)<br>View, comment, edit, and manage Sheets(sheets:spreadsheet)

### Request header

Parameter | Type | Required | Description
---|---|---|---
Authorization | string | Yes | `tenant_access_token`<br>or<br>`user_access_token`<br>**Value format**: "Bearer `access_token`"<br>**Example value**: "Bearer u-7f1bcd13fc57d46bac21793a18e560"<br>[How to choose and get access token](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-choose-which-type-of-token-to-use)
Content-Type | string | Yes | **Fixed value**: "application/json; charset=utf-8"

### Path parameters

Parameter | Type | Description
---|---|---
spreadsheet_token | string | Spreadsheet token<br>**Example value**: "Iow7sNNEphp3WbtnbCscPqabcef"
sheet_id | string | Sheet id<br>**Example value**: "PNIfrm"

### Request body

Parameter | Type | Required | Description
---|---|---|---
find_condition | find_condition | Yes | Search conditions
range | string | Yes | Search range, [glossary range](https://open.feishu.cn/document/ukTMukTMukTM/uATMzUjLwEzM14CMxMTN/overview)<br>**Example value**: "PNIfrm!A1:H10"
match_case | boolean | No | Whether it is case insensitive<br>- `true`: Ignore differences in case of letters in a string<br>- `false`: case sensitive<br>**Example value**: true
match_entire_cell | boolean | No | Whether to match the entire cell<br>- `true`: exact match<br>- `false`: partial match<br>**Example value**: false
search_by_regex | boolean | No | Whether it is regular expression matching<br>- `true`: regular match<br>- `false`: not regular match<br>**Example value**: false
include_formulas | boolean | No | Whether to search formula content<br>- `true`: search formula only<br>- `false`: Search cell contents only<br>**Example value**: false
find | string | Yes | Found string<br>**Example value**: "hello"
replacement | string | Yes | Replaced string<br>**Example value**: "world"

### Request body example
```json
{
    "find_condition": {
        "range": "PNIfrm!A1:H10",
        "match_case": true,
        "match_entire_cell": false,
        "search_by_regex": false,
        "include_formulas": false
    },
    "find": "hello",
    "replacement": "world"
}
```

## Response

### Response body

Parameter | Type | Description
---|---|---
code | int | Error codes, fail if not zero
msg | string | Error descriptions
data | \- | \-
replace_result | find_replace_result | Find and replace matching cell information
matched_cells | string\[\] | Array of cells that meet the search conditions, not including formulas, such as: ["A1", "A2"...]
matched_formula_cells | string\[\] | Array of cells that meet the search conditions including formulas, such as: ["B3", "H7"...]
rows_count | int | Total rows that meet search conditions

### Response body example
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "replace_result": {
            "matched_cells": [
                "A1"
            ],
            "matched_formula_cells": [
                "B3"
            ],
            "rows_count": 2
        }
    }
}
```

### Error code

HTTP status code | Error code | Description | Troubleshooting suggestions
---|---|---|---
400 | 1310242 | In Mix state | Retey Later
400 | 1310211 | Wrong Sheet Id | Check the sheet_id.
400 | 1310248 | Wrong Regular Expression | Check Regular Expression
400 | 1310202 | Wrong Range | Invalid range
400 | 1310229 | Wrong URL Param | Check the url parameter.
400 | 1310204 | Wrong Request Body | Check the request body parameter.
400 | 1310213 | Permission Fail | No permission
400 | 1310218 | Locked Cell | Check if the action targets a protected range.
400 | 1310214 | SpreadSheet Not Found | Check the spreadsheet token.
400 | 1310215 | Sheet Id Not Found | Check the sheet_id.
400 | 1310226 | Excess Limit | Exceeds the limit
400 | 1310217 | Too Many Request | Check if requests have been sent too frequently.
400 | 1310235 | Retry Later | Please try again later.
500 | 1315201 | Server Error | Internal service error. For more information, [contact support](https://applink.feishu.cn/client/helpdesk/open?id=6626260912531570952)
500 | 1315203 | Server Error | Internal service error. For more information, [contact support](https://applink.feishu.cn/client/helpdesk/open?id=6626260912531570952).
500 | 1315210 | Server Error | Internal service errors, please consult customer service for details
400 | 1310249 | Spreadsheet Deleted | Restore the form and try again

