Skip to Content
🎉 Univer 0.7.0 is released.Read more →
GuidesUniver SheetsFeaturesAnnotation

Note

Facade APIHas Paid PlanUniver ServerUniver on Node.jsPreset
---UniverSheetsNotePreset

Notes are a feature for adding comments to cells. Currently, adding and deleting notes is supported, and notes are always displayed on the right side of the cell.

This feature includes the following plugin packages:

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 { UniverSheetsNotePreset } from '@univerjs/presets/preset-sheets-note'; import UniverPresetSheetsNoteEnUS from '@univerjs/presets/preset-sheets-note/locales/en-US'; import '@univerjs/presets/lib/styles/preset-sheets-core.css' const { univerAPI } = createUniver({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: merge( {}, UniverPresetSheetsCoreEnUS, UniverPresetSheetsNoteEnUS ), }, theme: defaultTheme, presets: [ UniverSheetsCorePreset(), UniverSheetsNotePreset() ] });

Manual Combination Installation

npm install @univerjs/sheets-note @univerjs/sheets-note-ui
import { LocaleType, merge, Univer } from '@univerjs/core'; import { defaultTheme } from "@univerjs/design"; 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({ theme: defaultTheme, locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: merge( SheetsNoteEnUS, SheetsNoteUIEnUS ), }, }); univer.registerPlugin(UniverSheetsNotePlugin); univer.registerPlugin(UniverSheetsNoteUIPlugin);

Facade API 0.7.0+

To get full definition of facade api, please refer to FacadeAPI.

Get Annotation

FWorksheet.getNotes: Get all annotations in the worksheet

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const notes = fWorksheet.getNotes(); console.log(notes); notes.forEach((item) => { const { row, col, note } = item; console.log(`Cell ${fWorksheet.getRange(row, col).getA1Notation()} has a note: ${note}`); });

FRange.getNote: Get the annotation of the upper left cell in the range

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:D10'); const note = fRange.getNote(); console.log(note);

Create / Update Annotation

FRange.createOrUpdateNote: Create or update the annotation of the upper left cell in the range

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1'); fRange.createOrUpdateNote({ note: 'This is a note', width: 160, height: 100, show: true, });

Delete Annotation

FRange.deleteNote: Delete the annotation of the upper left cell in the range

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const notes = fWorksheet.getNotes(); console.log(notes); if (notes.length > 0) { // Delete the first note const { row, col } = notes[0]; fWorksheet.getRange(row, col).deleteNote(); } // Delete C1 note const fRange = fWorksheet.getRange('C1'); fRange.deleteNote();

Event Listening

Full event type definitions, please refer to Events.

Event NameDescription
SheetNoteAddTriggered after a note is added
SheetNoteDeleteTriggered after a note is deleted
SheetNoteUpdateTriggered after a note is updated
SheetNoteShowTriggered when a note is shown
SheetNoteHideTriggered when a note is hidden
BeforeSheetNoteAddTriggered before a note is added
BeforeSheetNoteDeleteTriggered before a note is deleted
BeforeSheetNoteUpdateTriggered before a note is updated
BeforeSheetNoteShowTriggered before a note is shown
BeforeSheetNoteHideTriggered before a note is hidden

Event Listening Example

// After annotation is added event const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteAdd, (params) => { const { workbook, worksheet, row, col, note } = params; console.log(params); }); // Remove the event listener, use `disposable.dispose()`
// Before annotation is deleted event, can be canceled const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteDelete, (params) => { const { workbook, worksheet, row, col, oldNote } = params; console.log(params); // Cancel the note deletion operation params.cancel = true; }); // Remove the event listener, use `disposable.dispose()`

Was this page helpful?
Last updated on