Notes
Une annotation fixe un commentaire à une cellule, de sorte que des informations supplémentaires ou un contexte restent à côté des données qu'elle décrit. Cette page explique comment lire, créer, mettre à jour et supprimer les annotations via le Facade API, et liste les événements qu'ils émettent.
Mode extension
Installation
pnpm add @univerjs/sheets-note @univerjs/sheets-note-uinpm install @univerjs/sheets-note @univerjs/sheets-note-uiyarn add @univerjs/sheets-note @univerjs/sheets-note-uibun add @univerjs/sheets-note @univerjs/sheets-note-uiUtilisation
import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import { UniverSheetsNotePlugin } from '@univerjs/sheets-note'import { UniverSheetsNoteUIPlugin } from '@univerjs/sheets-note-ui'import SheetsNoteEnUS from '@univerjs/sheets-note/locale/en-US'import SheetsNoteUIEnUS from '@univerjs/sheets-note-ui/locale/en-US'import '@univerjs/sheets-note-ui/lib/index.css'import '@univerjs/sheets-note/facade'const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( SheetsNoteEnUS, SheetsNoteUIEnUS, ), },})univer.registerPlugin(UniverSheetsNotePlugin)univer.registerPlugin(UniverSheetsNoteUIPlugin)Mode prédéfini
Installation
pnpm add @univerjs/preset-sheets-notenpm install @univerjs/preset-sheets-noteyarn add @univerjs/preset-sheets-notebun add @univerjs/preset-sheets-noteUtilisation
import { UniverSheetsCorePreset } from '@univerjs/preset-sheets-core'import UniverPresetSheetsCoreEnUS from '@univerjs/preset-sheets-core/locales/en-US'import { UniverSheetsNotePreset } from '@univerjs/preset-sheets-note'import UniverPresetSheetsNoteEnUS from '@univerjs/preset-sheets-note/locales/en-US'import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'import '@univerjs/preset-sheets-core/lib/index.css'import '@univerjs/preset-sheets-note/lib/index.css'const { univerAPI } = createUniver({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( UniverPresetSheetsCoreEnUS, UniverPresetSheetsNoteEnUS, ), }, presets: [ UniverSheetsCorePreset(), UniverSheetsNotePreset(), ],})Facade API
Les définitions de type Facade API complètes sont dans le FacadeAPI.
Importation
Note du mode greffon
Le paquet Facade est importé manuellement seulement en mode plugin. Le mode Preset inclut déjà le paquet correspondant.
import '@univerjs/sheets-note/facade'Récupérer les notes
FWorksheet.getNotes retourne chaque annotation de la feuille de travail.
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const notes = fWorksheet.getNotes()notes.forEach((item) => { const { row, col, note } = item console.log(`Cell ${fWorksheet.getRange(row, col).getA1Notation()} has note: ${note}`)})FRange.getNote retourne l'annotation sur la cellule supérieure gauche de la plage.
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const fRange = fWorksheet.getRange('A1:D10')const note = fRange.getNote()Ajouter ou mettre à jour des notes
FRange.createOrUpdateNote crée ou met à jour l'annotation sur la cellule supérieure gauche de la plage.
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const fRange = fWorksheet.getRange('A1')fRange.createOrUpdateNote({ note: 'This is an annotation', width: 160, height: 100, show: true,})Supprimer des notes
FRange.deleteNote supprime l'annotation sur la cellule supérieure gauche de la plage.
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const notes = fWorksheet.getNotes()if (notes.length > 0) { // Remove the first annotation in the worksheet const { row, col } = notes[0] fWorksheet.getRange(row, col).deleteNote()}// Remove the annotation in cell C1const fRange = fWorksheet.getRange('C1')fRange.deleteNote()Écouteurs d’événements
Les définitions complètes du type d'événement sont dans le Événements.
| Nom de l’événement | Description |
|---|---|
SheetNoteAdd | Incendie après l'ajout d'une annotation |
SheetNoteDelete | Incendie après la suppression d'une annotation |
SheetNoteUpdate | Feu après une annotation mise à jour |
SheetNoteShow | Feu lorsqu'une annotation est affichée |
SheetNoteHide | Feu quand une annotation est cachée |
BeforeSheetNoteAdd | Feu avant qu'une annotation ne soit ajoutée |
BeforeSheetNoteDelete | Feu avant qu'une annotation ne soit supprimée |
BeforeSheetNoteUpdate | Incendie avant la mise à jour d'une annotation |
BeforeSheetNoteShow | Feu avant qu'une annotation ne soit affichée |
BeforeSheetNoteHide | Feu avant qu'une annotation ne soit cachée |
Exemples d’écouteurs d’événements
// Triggered after adding an annotationconst disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteAdd, (params) => { const { workbook, worksheet, row, col, note } = params})// Remove event listener using `disposable.dispose()`// Triggered before removing an annotation, can be canceledconst disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteDelete, (params) => { const { workbook, worksheet, row, col, oldNote } = params // Cancel the annotation deletion operation params.cancel = true})// Remove event listener using `disposable.dispose()`Que pensez-vous de ce guide ?