Skip to content

Add notes and threaded comments ​

Use this page to annotate cells the way Excel 365 does, with plain notes or with conversation threads that name their authors and mention other people. Comments and notes covers the model, and the calls are under Comments and hyperlinks and Threaded comments and persons in the WASM API and the Python API.

Add a note ​

A note is Excel 365's name for the classic cell comment: a text box with an author name. setComment(cell, comment) writes one and null removes it. A note without an author reads back with author null (Python None), as every absent value does; an empty author string is stored as no author. listComments() returns every note on the sheet with its cell. A note is hidden until the pointer rests on the cell; setCommentVisible keeps it shown.

js
import createFormulon from '@libraz/formulon'

const formulon = await createFormulon()
const wb = formulon.Workbook.createDefault()
try {
  const ws = wb.sheet(0)
  ws.setComment('B2', { text: 'Check this figure', author: 'Ann' })
  ws.setComment('B3', { text: 'No author' })
  ws.setCommentVisible('B2', true)

  console.log(JSON.stringify(ws.getComment('B2'))) // {"text":"Check this figure","author":"Ann"}
  console.log(ws.getComment('B3').author) // null
  console.log(ws.getCommentVisible('B2')) // true
  console.log(JSON.stringify(ws.listComments()[0].cell)) // {"row":1,"col":1}

  ws.setComment('B2', null)
  console.log(ws.getComment('B2')) // null
} finally {
  wb.dispose()
}
python
from formulon import Comment, Workbook

with Workbook.create_default() as wb:
    ws = wb[0]
    ws.set_comment("B2", Comment("Check this figure", author="Ann"))
    ws.set_comment("B3", Comment("No author"))
    ws.set_comment_visible("B2", True)

    print(ws.get_comment("B2"))  # Comment(text='Check this figure', author='Ann')
    print(ws.get_comment("B3").author)  # None
    print(ws.get_comment_visible("B2"))  # True
    print(ws.list_comments()[0].cell)  # CellAddress(row=1, col=1)

    ws.set_comment("B2", None)
    print(ws.get_comment("B2"))  # None

A cell holds either a note or a thread, never both. Adding one to a cell that holds the other fails with StatusCode.AlreadyExists.

Register the people ​

Every threaded comment names its author by a person id from the workbook's person list. wb.addPerson adds a person and returns the id, a GUID in braces generated when you omit id. userId and providerId identify the account behind the name; leave them out for a person with no account.

js
import createFormulon from '@libraz/formulon'

const formulon = await createFormulon()
const wb = formulon.Workbook.createDefault()
try {
  const ann = wb.addPerson({ displayName: 'Ann Lee' })
  wb.addPerson({ displayName: 'Bob Kim', userId: '[email protected]', providerId: 'None' })

  console.log(/^\{[0-9A-F-]{36}\}$/.test(ann)) // true
  console.log(wb.listPeople().map((p) => p.displayName).join()) // Ann Lee,Bob Kim
  console.log(wb.getPerson(ann).userId) // null
} finally {
  wb.dispose()
}
python
import re

from formulon import PersonInput, Workbook

with Workbook.create_default() as wb:
    ann = wb.add_person(PersonInput(display_name="Ann Lee"))
    wb.add_person(PersonInput(display_name="Bob Kim", user_id="[email protected]", provider_id="None"))

    print(bool(re.fullmatch(r"\{[0-9A-F-]{36}\}", ann)))  # True
    print(",".join(p.display_name for p in wb.list_people()))  # Ann Lee,Bob Kim
    print(wb.get_person(ann).user_id)  # None

Start a thread and reply ​

addThreadedComment with a cell opens a thread there and returns the comment's id. A comment with a parentId is a reply to that thread, and its cell is ignored. listThreadedComments(cell) returns the thread in order, the opening comment first. created is the timestamp; the next section explains how it is read.

js
import createFormulon from '@libraz/formulon'

const formulon = await createFormulon()
const wb = formulon.Workbook.createDefault()
try {
  const ws = wb.sheet(0)
  const ann = wb.addPerson({ displayName: 'Ann Lee' })
  const bob = wb.addPerson({ displayName: 'Bob Kim' })

  const thread = ws.addThreadedComment({
    cell: 'C3',
    personId: ann,
    text: 'Is this total final?',
    created: new Date('2026-11-07T09:30:00Z'),
  })
  ws.addThreadedComment({
    parentId: thread,
    personId: bob,
    text: 'Yes, signed off.',
    created: new Date('2026-11-07T10:05:00Z'),
  })

  const comments = ws.listThreadedComments('C3')
  console.log(comments.length) // 2
  console.log(comments[1].text, comments[1].parentId === thread) // Yes, signed off. true
  console.log(wb.getPerson(comments[1].personId).displayName) // Bob Kim
} finally {
  wb.dispose()
}
python
from datetime import datetime, timezone

from formulon import PersonInput, ThreadedCommentInput, Workbook

with Workbook.create_default() as wb:
    ws = wb[0]
    ann = wb.add_person(PersonInput(display_name="Ann Lee"))
    bob = wb.add_person(PersonInput(display_name="Bob Kim"))

    thread = ws.add_threaded_comment(ThreadedCommentInput(
        cell="C3",
        person_id=ann,
        text="Is this total final?",
        created=datetime(2026, 11, 7, 9, 30, tzinfo=timezone.utc),
    ))
    ws.add_threaded_comment(ThreadedCommentInput(
        parent_id=thread,
        person_id=bob,
        text="Yes, signed off.",
        created=datetime(2026, 11, 7, 10, 5, tzinfo=timezone.utc),
    ))

    comments = ws.list_threaded_comments("C3")
    print(len(comments))  # 2
    print(comments[1].text, comments[1].parent_id == thread)  # Yes, signed off. True
    print(wb.get_person(comments[1].person_id).display_name)  # Bob Kim

save() writes each thread together with a note that tells older versions of Excel the cell holds a threaded comment. listComments() does not list those placeholder notes.

Set the timestamp in UTC ​

created is stored in UTC, and it is the one date input that reads a JavaScript Date through its UTC getters. Every other Date input, such as a cell value or a pinned clock, reads the local getters. So build a created value with Date.UTC(...) or an ISO string ending in Z, and build a cell date with new Date(year, monthIndex, day).

A CivilTime record passed as created is taken as UTC. Python reads a naive datetime in created as UTC and converts an aware one. Seconds are kept and milliseconds are dropped.

An omitted created is the current UTC time. When the workbook has a pinned clock (setPinnedNow), that wall-clock time is written as given, without conversion.

js
import createFormulon from '@libraz/formulon'

const formulon = await createFormulon()
const wb = formulon.Workbook.createDefault()
try {
  const ws = wb.sheet(0)
  const ann = wb.addPerson({ displayName: 'Ann Lee' })

  const id = ws.addThreadedComment({
    cell: 'B2',
    personId: ann,
    text: 'Logged at 09:30 UTC',
    created: new Date(Date.UTC(2026, 10, 7, 9, 30)),
  })
  console.log(JSON.stringify(ws.getThreadedComment(id).created)) // {"year":2026,"month":11,"day":7,"hour":9,"minute":30,"second":0}

  ws.setValue('A1', new Date(2026, 10, 7, 9, 30))
  const local = ws.getDate('A1')
  console.log(local.getHours(), local.getMinutes()) // 9 30
} finally {
  wb.dispose()
}
python
from datetime import datetime, timezone

from formulon import PersonInput, ThreadedCommentInput, Workbook

with Workbook.create_default() as wb:
    ws = wb[0]
    ann = wb.add_person(PersonInput(display_name="Ann Lee"))

    comment_id = ws.add_threaded_comment(ThreadedCommentInput(
        cell="B2",
        person_id=ann,
        text="Logged at 09:30 UTC",
        created=datetime(2026, 11, 7, 9, 30, tzinfo=timezone.utc),
    ))
    print(ws.get_threaded_comment(comment_id).created)  # 2026-11-07 09:30:00

    ws["A1"] = datetime(2026, 11, 7, 9, 30)
    print(ws.get_date("A1"))  # 2026-11-07 09:30:00

created reads back in UTC: a CivilTime record in JavaScript and a naive datetime in Python. Convert it to the reader's zone for display.

Mention a person ​

A mention ties a span of the comment text to a person: start and end are the half-open span [start, end), and the span usually covers the @Name text. Each binding counts the span in its own string indices: JavaScript in UTF-16 code units, as indexOf, length and slice do, and Python in code points, as str.index, len and slicing do.

The offsets of the same text differ between the two when it holds a character outside the Basic Multilingual Plane, such as most emoji, and neither needs a conversion.

js
import createFormulon from '@libraz/formulon'

const formulon = await createFormulon()
const wb = formulon.Workbook.createDefault()
try {
  const ws = wb.sheet(0)
  const ann = wb.addPerson({ displayName: 'Ann Lee' })
  const bob = wb.addPerson({ displayName: 'Bob Kim' })

  const text = '👍 @Bob Kim'
  const start = text.indexOf('@Bob Kim')
  const id = ws.addThreadedComment({
    cell: 'C3',
    personId: ann,
    text,
    mentions: [{ personId: bob, start, end: start + '@Bob Kim'.length }],
  })

  const [mention] = ws.getThreadedComment(id).mentions
  console.log(mention.start, mention.end) // 3 11
  console.log(text.slice(mention.start, mention.end), mention.personId === bob) // @Bob Kim true
} finally {
  wb.dispose()
}
python
from formulon import MentionInput, PersonInput, ThreadedCommentInput, Workbook

with Workbook.create_default() as wb:
    ws = wb[0]
    ann = wb.add_person(PersonInput(display_name="Ann Lee"))
    bob = wb.add_person(PersonInput(display_name="Bob Kim"))

    text = "👍 @Bob Kim"
    start = text.index("@Bob Kim")
    comment_id = ws.add_threaded_comment(ThreadedCommentInput(
        cell="C3",
        person_id=ann,
        text=text,
        mentions=[MentionInput(person_id=bob, start=start, end=start + len("@Bob Kim"))],
    ))

    mention = ws.get_threaded_comment(comment_id).mentions[0]
    print(mention.start, mention.end)  # 2 10
    print(text[mention.start:mention.end], mention.person_id == bob)  # @Bob Kim True

Resolve, edit and remove ​

updateThreadedComment(id, patch) changes a comment's text and mentions, and done resolves or reopens a thread; done is accepted on the opening comment only. removeThreadedComment(id) removes one comment.

js
import createFormulon from '@libraz/formulon'

const formulon = await createFormulon()
const wb = formulon.Workbook.createDefault()
try {
  const ws = wb.sheet(0)
  const ann = wb.addPerson({ displayName: 'Ann Lee' })
  const thread = ws.addThreadedComment({ cell: 'C3', personId: ann, text: 'Is this total final?' })
  const reply = ws.addThreadedComment({ parentId: thread, personId: ann, text: 'Draft reply' })

  ws.updateThreadedComment(reply, { text: 'Yes, signed off.' })
  ws.updateThreadedComment(thread, { done: true })
  console.log(ws.getThreadedComment(thread).done) // true
  console.log(ws.getThreadedComment(reply).text) // Yes, signed off.

  ws.removeThreadedComment(reply)
  console.log(ws.listThreadedComments('C3').length) // 1
} finally {
  wb.dispose()
}
python
from formulon import PersonInput, ThreadedCommentInput, Workbook

with Workbook.create_default() as wb:
    ws = wb[0]
    ann = wb.add_person(PersonInput(display_name="Ann Lee"))
    thread = ws.add_threaded_comment(ThreadedCommentInput(cell="C3", person_id=ann, text="Is this total final?"))
    reply = ws.add_threaded_comment(ThreadedCommentInput(parent_id=thread, person_id=ann, text="Draft reply"))

    ws.update_threaded_comment(reply, text="Yes, signed off.")
    ws.update_threaded_comment(thread, done=True)
    print(ws.get_threaded_comment(thread).done)  # True
    print(ws.get_threaded_comment(reply).text)  # Yes, signed off.

    ws.remove_threaded_comment(reply)
    print(len(ws.list_threaded_comments("C3")))  # 1