Interface: IFTextFinder
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);
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());
});
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());
}
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());
}
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());
}
matchCaseAsync()
matchCaseAsync(matchCase): Promise<IFTextFinder>
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);
matchEntireCellAsync()
matchEntireCellAsync(matchEntireCell): Promise<IFTextFinder>
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);
matchFormulaTextAsync()
matchFormulaTextAsync(matchFormulaText): Promise<IFTextFinder>
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);
replaceAllWithAsync()
replaceAllWithAsync(replaceText): Promise<number>
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);
replaceWithAsync()
replaceWithAsync(replaceText): Promise<boolean>
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);