Find & Replace
Facade API | Has Paid Plan | Univer Server | Univer on Node.js | Preset |
---|---|---|---|---|
✅ | - | - | - | UniverSheetsFindReplacePreset |
The Find and Replace plug-in provides the function of finding and replacing cells.
This feature includes the following plugin packages:
@univerjs/find-replace
- Fundamental Find and Replace Plugin@univerjs/sheets-find-replace
- Sheet Find and Replace Plugin
Presets Installation
import { createUniver, defaultTheme, LocaleType, merge } from '@univerjs/presets';
import { UniverSheetsCorePreset } from '@univerjs/presets/preset-sheets-core';
import UniverPresetSheetsCoreEnUS from '@univerjs/presets/preset-sheets-core/locales/en-US';
import { UniverSheetsFindReplacePreset } from '@univerjs/presets/preset-sheets-find-replace';
import UniverPresetSheetsFindReplaceEnUS from '@univerjs/presets/preset-sheets-find-replace/locales/en-US';
import '@univerjs/presets/lib/styles/preset-sheets-find-replace.css'
const { univerAPI } = createUniver({
locale: LocaleType.EN_US,
locales: {
[LocaleType.EN_US]: merge(
{},
UniverPresetSheetsCoreEnUS,
UniverPresetSheetsFindReplaceEnUS
),
},
theme: defaultTheme,
presets: [
UniverSheetsCorePreset(),
UniverSheetsFindReplacePreset(),
],
});
Piecemeal Installation
npm install @univerjs/find-replace @univerjs/sheets-find-replace
import { LocaleType, merge, Univer } from '@univerjs/core';
import { defaultTheme } from "@univerjs/design";
import { UniverFindReplacePlugin } from '@univerjs/find-replace';
import { UniverSheetsFindReplacePlugin } from '@univerjs/sheets-find-replace';
import FindReplaceEnUS from '@univerjs/find-replace/locale/en-US';
import SheetsFindReplaceEnUS from '@univerjs/sheets-find-replace/locale/en-US';
import '@univerjs/find-replace/lib/index.css';
import '@univerjs/sheets-find-replace/facade';
const univer = new Univer({
theme: defaultTheme,
locale: LocaleType.EN_US,
locales: {
[LocaleType.EN_US]: merge(
FindReplaceEnUS,
SheetsFindReplaceEnUS
),
},
});
univer.registerPlugin(UniverFindReplacePlugin);
univer.registerPlugin(UniverSheetsFindReplacePlugin);
Facade API
To get full defination of facade api, please refer to FacadeAPI
Create Text Finder
univerAPI.createTextFinderAsync()
creates a text finder and returns an FTextFinder
instance.
Here are some member methods on FTextFinder
:
Method | Description |
---|---|
findAll | Get all the matched cells of the current sheet, the current matched cell is the last matched cell |
findNext | Get the next matched cell of the current sheet, if exists return the next matched cell and move the current matched cell to the next matched cell |
findPrevious | Get the previous matched cell of the current sheet, if exists return the previous matched cell and move the current matched cell to the previous matched cell |
getCurrentMatch | Get the current matched cell of the current sheet |
matchCaseAsync | Set the match case option, if true, the find operation will match case, otherwise, the find operation will ignore case |
matchEntireCellAsync | Set the match entire cell option, if true, the find operation will match entire cell value, otherwise, the find operation will match part of the cell value |
matchFormulaTextAsync | Set the match formula text option, if true, the find operation will match formula text, otherwise, the find operation will match value |
replaceAllWithAsync | Replace all the matched text with the given text |
replaceWithAsync | Replace the current matched text with the given text |
ensureCompleteAsync | Ensure the find operation is completed. Especially when the current sheet changed use this method to ensure the find operation is completed |
// Assume the current sheet is empty sheet.
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// Set some values to the range A1:D10.
const fRange = fWorksheet.getRange('A1:D10');
fRange.setValues([
[1, 2, 3, 4],
[2, 3, 4, 5],
[3, 4, 5, 6],
[4, 5, 6, 7],
[5, 6, 7, 8],
[6, 7, 8, 9],
[7, 8, 9, 10],
[8, 9, 10, 11],
[9, 10, 11, 12],
[10, 11, 12, 13]
]);
// Create a text-finder to find the text '5'.
const textFinder = await univerAPI.createTextFinderAsync('5');
// Find all cells that contain the text '5'.
const matchCells = textFinder.findAll();
matchCells.forEach((cell) => {
console.log(cell.getA1Notation()); // D2, C3, B4, A5
});
Last updated on