@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
Parameter | Type |
---|---|
_initialState | Partial <IFindReplaceState > |
_injector | Injector |
_univerInstanceService | IUniverInstanceService |
_findReplaceService | IFindReplaceService |
Returns
Overrides
Properties
Property | Modifier | Type | Default value | Inherited from | Defined in |
---|---|---|---|---|---|
_disposed | protected | boolean | false | Disposable ._disposed | core/src/shared/lifecycle.ts:96 |
Methods
dispose()
dispose(): void
Defined in: core/src/shared/lifecycle.ts:109
Returns
void
Inherited from
disposeWithMe()
disposeWithMe(disposable): IDisposable
Defined in: core/src/shared/lifecycle.ts:99
Parameters
Parameter | Type |
---|---|
disposable | DisposableLike |
Returns
Inherited from
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
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
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
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
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
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
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
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
matchCaseAsync()
matchCaseAsync(matchCase): Promise<IFTextFinder>
Defined in: sheets-find-replace/src/facade/f-text-finder.ts:217
set the match case option
Parameters
Parameter | Type | Description |
---|---|---|
matchCase | boolean | whether to match case |
Returns
Promise
<IFTextFinder
>
text-finder instance
Example
const textFinder = await univerAPI.createTextFinderAsync('hello');
await textFinder.matchCaseAsync(true);
Implementation of
matchEntireCellAsync()
matchEntireCellAsync(matchEntireCell): Promise<IFTextFinder>
Defined in: sheets-find-replace/src/facade/f-text-finder.ts:229
set the match entire cell option
Parameters
Parameter | Type | Description |
---|---|---|
matchEntireCell | boolean | whether 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
Parameter | Type | Description |
---|---|---|
matchFormulaText | boolean | whether 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
Parameter | Type | Description |
---|---|---|
replaceText | string | the 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
Parameter | Type | Description |
---|---|---|
replaceText | string | the 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);