Anotaciones

Headless compatible

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

Shell
pnpm add @univerjs/sheets-note @univerjs/sheets-note-ui

Uso

TypeScript
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

Shell
pnpm add @univerjs/preset-sheets-note

Uso

TypeScript
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.

TypeScript
import '@univerjs/sheets-note/facade'

Obtener anotaciones

FWorksheet.getNotes devuelve cada anotación en la hoja de trabajo.

TypeScript
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.

TypeScript
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.

TypeScript
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.

TypeScript
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 NombreDescripción
SheetNoteAddFuegos después de que se añada una anotación
SheetNoteDeleteFuegos después de una anotación se elimina
SheetNoteUpdateFuegos después de una anotación se actualiza
SheetNoteShowFuegos cuando se muestra una anotación
SheetNoteHideFuegos cuando una anotación está oculta
BeforeSheetNoteAddFuegos antes de que se añada una anotación
BeforeSheetNoteDeleteFuegos antes de que se suprima una anotación
BeforeSheetNoteUpdateFuegos antes de que se actualice una anotación
BeforeSheetNoteShowFuegos antes de que se muestre una anotación
BeforeSheetNoteHideFuegos antes de que se oculte una anotación
Ejemplos de escuchas de eventos
TypeScript
// 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()`
TypeScript
// 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?

© 2026 DreamNum Co., Ltd.