word/comments.xmlpart — comment bodies + author/date/initials (§17.13.4).
Module docxComments | Source packages/front/office/ooxml/src/docx/comments.js | Deps ooxmlErrors, xml, docxStructure, ooxmlShared | Worker-safe yes
Comments live in a dedicated part. In the body they are anchored by the <w:commentRangeStart> / <w:commentRangeEnd> / <w:commentReference> triple — handled by docx-structure.
Resolve
const com = runtime.resolve('docxComments');
// Returns: { parse, serialize, bytesOf,
// REL_TYPE_COMMENTS, CT_COMMENTS }
API
| Method | Signature | Returns |
|---|---|---|
parse |
(input: text|bytes|XmlElement) => commentsObj |
Typed model. An already-parsed root element is used as is. |
serialize |
(obj) => string |
<w:comments> XML. |
bytesOf |
(obj) => Uint8Array |
UTF-8 bytes. |
REL_TYPE_COMMENTS, CT_COMMENTS |
string | OPC bindings. |
Model
{
comments: [{
id: number,
author?: string,
date?: string, // ISO 8601
initials?: string,
body: [paragraph | table],
_extras?: [xmlNode]
}],
_extras?: [xmlNode]
}
Examples
Add a comment
const com = runtime.resolve('docxComments');
const obj = {
comments: [{
id: 1, author: 'Alice', initials: 'AB',
date: '2024-01-15T10:00:00Z',
body: [d.paragraph('Really?')]
}]
};
d.write(doc, { comments: obj });
// The body-side anchoring uses a run child of type 'commentReference'
// plus w:commentRangeStart/End — see docx-structure.
Read
const obj = com.parse(pkg.parts['/word/comments.xml']);
obj.comments.map(c => `${c.author}: ${docx.toText({ body: c.body })}`);
Notes
idis a per-file unique integer. The body'scommentReferenceuses the sameid(as a string).bodyis typed like a regular docx body — tables, lists and so on are accepted.- The
commentRangeStart/commentRangeEndanchors must surround the commented content; without them Word shows an orphan comment. - A bad root element raises
ParseError('docx/comments-bad-root')— seeooxmlErrors. docx.readpasses a root already processed bymarkupCompatibility(ignorable extension content dropped, the two repeating-section elements kept); a standalone call on text or bytes does no markup-compatibility processing.- The written root declares
wandr, plusmc,w15andmc:Ignorable="w15"when the part holds aw15element. - For the Office 2018+ threaded model,
@awacloud/ooxmlimplements it on the spreadsheet side only — seexlsx-threaded-comments.
See also
- docx —
writewithcomments. - docx-structure — body-side anchor markers.