Anotaciones
Una anotación adjunta un comentario a una célula, por lo que la información adicional o el contexto sigue junto a los datos que describe. Esta página explica cómo leer, crear, actualizar y eliminar anotaciones a través de la Facade API, y enumera los eventos que emiten.
Modo complemento
Instalación
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-uiUso
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)Modo predeterminado
Instalación
pnpm add @univerjs/preset-sheets-notenpm install @univerjs/preset-sheets-noteyarn add @univerjs/preset-sheets-notebun add @univerjs/preset-sheets-noteUso
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(), ],})API de Facade
Las definiciones completas del tipo Facade API están en el FacadeAPI.
Importar
Nota del modo Plugin
El paquete Facade se importa manualmente sólo en modo plugin. El modo Preset ya incluye el paquete correspondiente.
import '@univerjs/sheets-note/facade'Obtener anotaciones
FWorksheet.getNotes devuelve cada anotación en la hoja de trabajo.
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 devuelve la anotación en la célula superior izquierda de la gama.
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const fRange = fWorksheet.getRange('A1:D10')const note = fRange.getNote()Agregar o actualizar anotaciones
FRange.createOrUpdateNote crea o actualiza la anotación en la célula superior izquierda del rango.
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,})Eliminar anotaciones
FRange.deleteNote elimina la anotación en la célula superior izquierda del rango.
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()Escuchas de eventos
Las definiciones completas del tipo de evento están en el Eventos.
| Evento Nombre | Descripción |
|---|---|
SheetNoteAdd | Fuegos después de que se añada una anotación |
SheetNoteDelete | Fuegos después de una anotación se elimina |
SheetNoteUpdate | Fuegos después de una anotación se actualiza |
SheetNoteShow | Fuegos cuando se muestra una anotación |
SheetNoteHide | Fuegos cuando una anotación está oculta |
BeforeSheetNoteAdd | Fuegos antes de que se añada una anotación |
BeforeSheetNoteDelete | Fuegos antes de que se suprima una anotación |
BeforeSheetNoteUpdate | Fuegos antes de que se actualice una anotación |
BeforeSheetNoteShow | Fuegos antes de que se muestre una anotación |
BeforeSheetNoteHide | Fuegos antes de que se oculte una anotación |
Ejemplos de escuchas de eventos
// 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()`¿Cómo es esta guía?