pyopenxlsx supports adding and interacting with standard comments, as well as the modern Threaded Comments (used in newer versions of Excel for conversational replies).
You must first register a “Person” (an author) in the workbook before adding threaded comments.
frompyopenxlsximportWorkbookwithWorkbook()aswb:ws=wb.active# 1. Register a Person in the documentpersons=wb._doc.persons()author_id=persons.add_person("John Doe")# 2. Access the threaded comments collection for the active sheetthreads=ws._sheet.threaded_comments()# 3. Add a top-level comment to a cell (e.g. A1)root_comment=threads.add_comment("A1",author_id,"Please update these figures.")# 4. Add a reply to the root comment# Notice we pass the parent's IDreply=threads.add_reply(root_comment.id,author_id,"Updated!")# 5. Mark the conversation as resolvedroot_comment.is_resolved=Truewb.save("threaded_comments.xlsx")
You can load an existing workbook and retrieve conversation threads:
frompyopenxlsximportload_workbookwithload_workbook("threaded_comments.xlsx")aswb:ws=wb.activethreads=ws._sheet.threaded_comments()# Get the root comment on a specific cellc=threads.comment("A1")ifc.valid:print(f"Top Comment: '{c.text}' (Resolved: {c.is_resolved})")# Get all repliesreplies=threads.replies(c.id)forrinreplies:print(f" Reply: '{r.text}'")
(Note: Advanced Threaded Comments API is accessed via the internal C++ bindings ._doc and ._sheet properties to offer raw maximum control over the underlying OpenXLSX objects).
Comments API
pyopenxlsxsupports adding and interacting with standard comments, as well as the modern Threaded Comments (used in newer versions of Excel for conversational replies).Adding Legacy Comments
A standard, non-threaded comment attached to a cell.
Threaded Comments
Threaded comments support rich conversations with authors (persons), replies, and resolved states.
Interacting with Threaded Comments
You must first register a “Person” (an author) in the workbook before adding threaded comments.
Reading Threaded Comments
You can load an existing workbook and retrieve conversation threads:
(Note: Advanced Threaded Comments API is accessed via the internal C++ bindings
. _docand._sheetproperties to offer raw maximum control over the underlying OpenXLSX objects).