@univerjs/sheets-find-replace v0.5.4


Class: FTextFinder

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:158

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

Extends

Implements

Constructors

new FTextFinder()

new FTextFinder(
   _initialState, 
   _injector, 
   _univerInstanceService, 
   _findReplaceService): FTextFinder

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:162

Parameters

ParameterType
_initialStatePartial<IFindReplaceState>
_injectorInjector
_univerInstanceServiceIUniverInstanceService
_findReplaceServiceIFindReplaceService

Returns

FTextFinder

Overrides

Disposable.constructor

Properties

PropertyModifierTypeDefault valueInherited fromDefined in
_disposedprotectedbooleanfalseDisposable._disposedcore/src/shared/lifecycle.ts:96

Methods

dispose()

dispose(): void

Defined in: core/src/shared/lifecycle.ts:109

Returns

void

Inherited from

Disposable.dispose


disposeWithMe()

disposeWithMe(disposable): IDisposable

Defined in: core/src/shared/lifecycle.ts:99

Parameters

ParameterType
disposableDisposableLike

Returns

IDisposable

Inherited from

Disposable.disposeWithMe


ensureCompleteAsync()

ensureCompleteAsync(): Promise<Nullable<IFindComplete>>

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:267

ensure the find operation is completed

Returns

Promise<Nullable<IFindComplete>>

the find complete result

Example

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

Implementation of

IFTextFinder.ensureCompleteAsync


ensureNotDisposed()

protected ensureNotDisposed(): void

Defined in: core/src/shared/lifecycle.ts:103

Returns

void

Inherited from

Disposable.ensureNotDisposed


findAll()

findAll(): FRange[]

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:178

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>

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:187

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>

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:198

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>

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:206

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>

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:217

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>

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:229

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>

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:241

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>

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:253

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>

Defined in: sheets-find-replace/src/facade/f-text-finder.ts:260

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