Class TextFinder

  • TextFinder is used to find or replace text within a range, sheet, or spreadsheet with customizable search options.

  • Key methods include finding all matches, navigating through matches, getting the current match, and replacing text.

  • Search behavior can be configured to ignore diacritics, match case, match entire cells, or search within formulas.

  • TextFinder allows starting a search from a specific range and supports using regular expressions.

TextFinder

Find or replace text within a range, sheet or spreadsheet. Can also specify search options.

Methods

MethodReturn typeBrief description
findAll()Range[]Returns all cells matching the search criteria.
findNext()RangeReturns the next cell matching the search criteria.
findPrevious()RangeReturns the previous cell matching the search criteria.
getCurrentMatch()RangeReturns the current cell matching the search criteria.
ignoreDiacritics(ignoreDiacritics)TextFinderIftrue, configures the search to ignore diacritics while matching; otherwise thesearch matches diacritics.
matchCase(matchCase)TextFinderIftrue, configures the search to match the search text's case exactly, otherwise thesearch defaults to case-insensitive matching.
matchEntireCell(matchEntireCell)TextFinderIftrue, configures the search to match the entire contents of a cell; otherwise, thesearch defaults to partial matching.
matchFormulaText(matchFormulaText)TextFinderIftrue, configures the search to return matches that appear within formula text;otherwise cells with formulas are considered based on their displayed value.
replaceAllWith(replaceText)IntegerReplaces all matches with the specified text.
replaceWith(replaceText)IntegerReplaces the search text in the currently matched cell with the specified text and returns thenumber of occurrences replaced.
startFrom(startRange)TextFinderConfigures the search to start searching immediately after the specified cell range.
useRegularExpression(useRegEx)TextFinderIftrue, configures the search to interpret the search string as a regular expression;otherwise the search interprets the search string as normal text.

Detailed documentation

findAll()

Returns all cells matching the search criteria.

Return

Range[] — All the matching cells.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

findNext()

Returns the next cell matching the search criteria.

Return

Range — The next matching cell, ornull if there are no previous matches.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

findPrevious()

Returns the previous cell matching the search criteria.

Return

Range — The previous matching cell, ornull if there are no previous matches.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getCurrentMatch()

Returns the current cell matching the search criteria.

Return

Range — The current matching cell, ornull if there are no further matches.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

ignoreDiacritics(ignoreDiacritics)

Iftrue, configures the search to ignore diacritics while matching; otherwise thesearch matches diacritics. A diacritic is a sign, such as an accent or cedilla, which whenwritten above or below a letter indicates a difference in pronunciation from the same letterwhen unmarked or differently marked.

Parameters

NameTypeDescription
ignoreDiacriticsBooleanWhether the search considers diacritics.

Return

TextFinder — This text finder, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

matchCase(matchCase)

Iftrue, configures the search to match the search text's case exactly, otherwise thesearch defaults to case-insensitive matching.

Parameters

NameTypeDescription
matchCaseBooleanWhether the matching is case-sensitive.

Return

TextFinder — This text finder, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

matchEntireCell(matchEntireCell)

Iftrue, configures the search to match the entire contents of a cell; otherwise, thesearch defaults to partial matching.

Parameters

NameTypeDescription
matchEntireCellBooleanWhether the entire cell is matched.

Return

TextFinder — This text finder, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

matchFormulaText(matchFormulaText)

Iftrue, configures the search to return matches that appear within formula text;otherwise cells with formulas are considered based on their displayed value.

Parameters

NameTypeDescription
matchFormulaTextBooleanWhether the search examines formula text.

Return

TextFinder — This text finder, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

replaceAllWith(replaceText)

Replaces all matches with the specified text. Returns the number of occurrences replaced, whichmay be different from the number of matched cells.

Parameters

NameTypeDescription
replaceTextStringThe text that replaces the text in the matched cells.

Return

Integer — The number of occurrences replaced.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

replaceWith(replaceText)

Replaces the search text in the currently matched cell with the specified text and returns thenumber of occurrences replaced.

Parameters

NameTypeDescription
replaceTextStringThe text that replaces the content in the currently matched cell.

Return

Integer — The number of occurrences replaced.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

startFrom(startRange)

Configures the search to start searching immediately after the specified cell range.

Parameters

NameTypeDescription
startRangeRangeThe cell range after which the search should start.

Return

TextFinder — This text finder, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

useRegularExpression(useRegEx)

Iftrue, configures the search to interpret the search string as a regular expression;otherwise the search interprets the search string as normal text. For more details on how touse regular expressions, refer to theFind and replace support page.

Parameters

NameTypeDescription
useRegExBooleanWhether to interpret the search string as a regular expression.

Return

TextFinder — This text finder, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.