查找或替换某个范围、工作表或电子表格中的文本。也可以指定搜索选项。
方法
方法 | 返回类型 | 简介 |
---|---|---|
findAll() | Range[] | 返回符合搜索条件的所有单元格。 |
findNext() | Range | 返回符合搜索条件的下一个单元格。 |
findPrevious() | Range | 返回符合搜索条件的上一个单元格。 |
getCurrentMatch() | Range | 返回符合搜索条件的当前单元格。 |
ignoreDiacritics(ignoreDiacritics) | TextFinder | 如果为 true ,则将搜索配置为在匹配时忽略变音符号;否则,搜索匹配变音符号。 |
matchCase(matchCase) | TextFinder | 如果为 true ,则将搜索配置为与搜索文本完全匹配,否则将默认搜索不区分大小写。 |
matchEntireCell(matchEntireCell) | TextFinder | 如果为 true ,则将搜索配置为匹配单元格的全部内容;否则,搜索默认为部分匹配。 |
matchFormulaText(matchFormulaText) | TextFinder | 如果为 true ,则将搜索配置为返回公式文本中显示的匹配项;否则,根据公式的显示值考虑包含公式的单元格。 |
replaceAllWith(replaceText) | Integer | 使用指定文本替换所有匹配项。 |
replaceWith(replaceText) | Integer | 将当前匹配的单元格中的搜索文本替换为指定文本,并返回替换次数。 |
startFrom(startRange) | TextFinder | 将搜索配置为在指定的单元格范围之后立即开始搜索。 |
useRegularExpression(useRegEx) | TextFinder | 如果为 true ,则将搜索配置为将搜索字符串解读为正则表达式;否则,搜索会将搜索字符串解读为普通文本。 |
详细文档
findAll()
findNext()
findPrevious()
getCurrentMatch()
ignoreDiacritics(ignoreDiacritics)
如果为 true
,则将搜索配置为在匹配时忽略变音符号;否则,搜索匹配变音符号。变音符号是一个变音符号或变音符号,表示在字母上方或下方写出的变音与原字母的发音差异。
参数
名称 | 类型 | 说明 |
---|---|---|
ignoreDiacritics | Boolean | 搜索是否考虑变音符号。 |
返回
TextFinder
- 此文本查找器,用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
matchCase(matchCase)
如果为 true
,则将搜索配置为与搜索文本完全匹配,否则将默认搜索不区分大小写。
参数
名称 | 类型 | 说明 |
---|---|---|
matchCase | Boolean | 匹配是否区分大小写。 |
返回
TextFinder
- 此文本查找器,用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
matchEntireCell(matchEntireCell)
如果为 true
,则将搜索配置为匹配单元格的全部内容;否则,搜索默认为部分匹配。
参数
名称 | 类型 | 说明 |
---|---|---|
matchEntireCell | Boolean | 是否匹配整个单元格。 |
返回
TextFinder
- 此文本查找器,用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
matchFormulaText(matchFormulaText)
如果为 true
,则将搜索配置为返回公式文本中显示的匹配项;否则,根据公式的显示值考虑包含公式的单元格。
参数
名称 | 类型 | 说明 |
---|---|---|
matchFormulaText | Boolean | 搜索是否检查公式文本。 |
返回
TextFinder
- 此文本查找器,用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
replaceAllWith(replaceText)
使用指定文本替换所有匹配项。返回替换的发生次数,可能与匹配的单元格数不同。
参数
名称 | 类型 | 说明 |
---|---|---|
replaceText | String | 替换匹配单元格中的文本的文本。 |
返回
Integer
- 替换的发生次数。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
replaceWith(replaceText)
将当前匹配的单元格中的搜索文本替换为指定文本,并返回替换次数。
参数
名称 | 类型 | 说明 |
---|---|---|
replaceText | String | 替换当前匹配单元格中的内容的文本。 |
返回
Integer
- 替换的发生次数。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
startFrom(startRange)
将搜索配置为在指定的单元格范围之后立即开始搜索。
参数
名称 | 类型 | 说明 |
---|---|---|
startRange | Range | 应在其中开始搜索的单元格范围。 |
返回
TextFinder
- 此文本查找器,用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
useRegularExpression(useRegEx)
如果为 true
,则将搜索配置为将搜索字符串解读为正则表达式;否则,搜索会将搜索字符串解读为普通文本。如需详细了解如何使用正则表达式,请参阅查找和替换支持页面。
参数
名称 | 类型 | 说明 |
---|---|---|
useRegEx | Boolean | 是否将搜索字符串解读为正则表达式。 |
返回
TextFinder
- 此文本查找器,用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets