Skip to Content
ClassesFTextFinder

Class: FTextFinder

This interface class provides methods to find and replace text in the univer.

Extends

  • any

Implements

Methods

ensureCompleteAsync()

ensureCompleteAsync(): Promise<any>

ensure the find operation is completed

Returns

Promise<any>

the find complete result

Example

const textFinder = await univerAPI.createTextFinderAsync('hello'); const complete = await textFinder.ensureCompleteAsync(); console.log(complete);

Implementation of

IFTextFinder.ensureCompleteAsync


findAll()

findAll(): FRange[]

get all the matched range in the univer

Returns

FRange[]

all the matched range

Throws

if the find operation is not completed

Example

const textFinder = await univerAPI.createTextFinderAsync('hello'); const ranges = textFinder.findAll(); ranges.forEach((range) => { console.log(range.getA1Notation()); });

Implementation of

IFTextFinder.findAll


findNext()

findNext(): Nullable<FRange>

find the next matched range in the univer

Returns

Nullable<FRange>

the next matched range

null if no more match

Throws

if the find operation is not completed

Example

const textFinder = await univerAPI.createTextFinderAsync('hello'); const range = textFinder.findNext(); if (range) { console.log(range.getA1Notation()); }

Implementation of

IFTextFinder.findNext


findPrevious()

findPrevious(): Nullable<FRange>

find the previous matched range in the univer

Returns

Nullable<FRange>

the previous matched range

null if no more match

Throws

if the find operation is not completed

Example

const textFinder = await univerAPI.createTextFinderAsync('hello'); const range = textFinder.findPrevious(); if (range) { console.log(range.getA1Notation()); }

Implementation of

IFTextFinder.findPrevious


getCurrentMatch()

getCurrentMatch(): Nullable<FRange>

get the current matched range in the univer

Returns

Nullable<FRange>

the current matched range

Throws

if the find operation is not completed

Example

const textFinder = await univerAPI.createTextFinderAsync('hello'); const range = textFinder.getCurrentMatch(); if (range) { console.log(range.getA1Notation()); }

Implementation of

IFTextFinder.getCurrentMatch


matchCaseAsync()

matchCaseAsync(matchCase): Promise<IFTextFinder>

set the match case option

Parameters

ParameterTypeDescription
matchCasebooleanwhether to match case

Returns

Promise<IFTextFinder>

text-finder instance

Example

const textFinder = await univerAPI.createTextFinderAsync('hello'); await textFinder.matchCaseAsync(true);

Implementation of

IFTextFinder.matchCaseAsync


matchEntireCellAsync()

matchEntireCellAsync(matchEntireCell): Promise<IFTextFinder>

set the match entire cell option

Parameters

ParameterTypeDescription
matchEntireCellbooleanwhether to match entire cell

Returns

Promise<IFTextFinder>

text-finder instance

Example

const textFinder = await univerAPI.createTextFinderAsync('hello'); await textFinder.matchEntireCellAsync(true);

Implementation of

IFTextFinder.matchEntireCellAsync


matchFormulaTextAsync()

matchFormulaTextAsync(matchFormulaText): Promise<IFTextFinder>

set the match formula text option

Parameters

ParameterTypeDescription
matchFormulaTextbooleanwhether to match formula text

Returns

Promise<IFTextFinder>

text-finder instance

Example

const textFinder = await univerAPI.createTextFinderAsync('hello'); await textFinder.matchFormulaTextAsync(true);

Implementation of

IFTextFinder.matchFormulaTextAsync


replaceAllWithAsync()

replaceAllWithAsync(replaceText): Promise<number>

replace all the matched text with the given text

Parameters

ParameterTypeDescription
replaceTextstringthe text to replace

Returns

Promise<number>

the number of replaced text

Throws

if the find operation is not completed

Example

const textFinder = await univerAPI.createTextFinderAsync('hello'); const replacedCount = await textFinder.replaceAllWithAsync('world'); console.log(replacedCount);

Implementation of

IFTextFinder.replaceAllWithAsync


replaceWithAsync()

replaceWithAsync(replaceText): Promise<boolean>

replace the current matched text with the given text

Parameters

ParameterTypeDescription
replaceTextstringthe text to replace

Returns

Promise<boolean>

whether the replace is successful

Throws

if the find operation is not completed

Example

const textFinder = await univerAPI.createTextFinderAsync('hello'); const replaced = await textFinder.replaceWithAsync('world'); console.log(replaced);

Implementation of

IFTextFinder.replaceWithAsync