The text of comments is in word/comments.xml, reached by the main
document’s comments relationship. The main text says only where each comment
is attached.
Anchors in the text
<w:p>
<w:commentRangeStart w:id="3"/>
<w:r><w:t>the commented words</w:t></w:r>
<w:commentRangeEnd w:id="3"/>
<w:r>
<w:rPr><w:rStyle w:val="CommentReference"/></w:rPr>
<w:commentReference w:id="3"/>
</w:r>
</w:p>
The range can cover several paragraphs, or be absent, leaving just the reference.
The comments part
<w:comments xmlns:w="…">
<w:comment w:id="3" w:author="Ada Example" w:initials="AE" w:date="2024-05-17T13:45:00Z">
<w:p>
<w:pPr><w:pStyle w:val="CommentText"/></w:pPr>
<w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:annotationRef/></w:r>
<w:r><w:t>Could this be shorter?</w:t></w:r>
</w:p>
</w:comment>
</w:comments>
| Attribute | Meaning |
|---|---|
w:id | What the anchors in the text name. |
w:author, w:initials | Who wrote it: free text. |
w:date | When, as an ISO 8601 date and time. |
Authors’ names in comments, and those in tracked changes, stay in the file until they are removed.
Replies and resolved comments
The base format has no threads. Later versions of Word added further parts, tied to the
comments by the w14:paraId on each comment’s last paragraph:
Source: [MS-DOCX] 2.1.2–2.1.5 (parts), 2.5.1.5, 2.5.1.9, 2.5.3.1–2.5.3.6 (w15), 2.6.2.3 (w14:paraId), 2.8 (cid), 2.9 and 2.10 (cex) and the schemas in sections 5.4–5.6, all read from the specification text. Every attribute in these schemas is namespace-qualified (attributeFormDefault="qualified"). The part names below are the usual ones; a part is found by its relationship from the main part, not by name. [MS-DOCX] does not state the relationship types or content types of these parts.
| Part (root element) | Elements and attributes | Meaning ([MS-DOCX]) |
|---|---|---|
commentsExtended (w15:commentsEx, 2.5.1.5; not in Word 2010 and earlier) | w15:commentEx, any number (2.5.3.1): w15:paraId (required), w15:paraIdParent (optional), w15:done (optional ST_OnOff) | paraId is the w14:paraId of the last paragraph of the comment. paraIdParent is the paraId of the last paragraph of the comment that this one replies to. done 1: a user marked the comment done; 0 (the default): not done. |
commentsIds (w16cid:commentsIds, 2.8.1.1; not in Word 2013 and earlier) | w16cid:commentId, any number (2.8.3.1): w16cid:paraId and w16cid:durableId, both required, ST_LongHexNumber | paraId is that of the last paragraph of the comment. durableId identifies the comment and must be greater than 0 and less than 0x7FFFFFFF. |
commentsExtensible (w16cex:commentsExtensible, 2.10.1.1; not in Word 2016 and earlier) | w16cex:commentExtensible, any number, then an optional extLst (2.10.3.2). Each has durableId (required), dateUtc (ST_DateTime), intelligentPlaceholder (ST_OnOff) and an optional extLst of ext elements, each with a uri (2.9.3.1, 2.9.3.2, 2.10.3.1) | durableId is the one in commentsIds. dateUtc is the comment's date in UTC, unlike w:date, which Word writes in local time. intelligentPlaceholder true marks a follow-up; it must not be on a reply, and the content of such a comment should be ignored. The one extension the spec lists (2.2.13) has URI {CE6994B0-6A32-4C9F-8C6B-6E91EDA988CE} and holds reactions11 from [MS-OREACTXML], which is not in the research folder and so is not decoded. |
people (w15:people, 2.5.1.9; not in Word 2010 and earlier) | w15:person, any number (2.5.3.5): w15:author (required) and an optional w15:presenceInfo (2.5.3.6) with w15:providerId and w15:userId (both required) | One entry per person who authored at least one comment or revision; author must match the author of at least one. Provider None: userId is the author's name. AD: an Active Directory SID ([MS-DTYP] 2.4.2), or for Office 365 a string of three values separated by ::. Windows Live: a 64-bit signed decimal. |
The viewer links the four parts to the comments through paraId (the w14:paraId of each comment's last paragraph, compared as upper-case hexadecimal) and durableId, and the Comments table in the Overview shows, for each comment: the reply parent (the id of the comment it answers; a parent that matches no comment is named by its paragraph id), resolved or open, the paragraph id, the durable id, the UTC date, a follow-up flag and the extension URIs. The People table shows author, provider and user id. Parts that are absent leave their columns empty; w15:done counts as resolved for 1, true or on.
Comments in detail
Compared with ECMA-376 Part 1 §17.13.4.1–17.13.4.6,
CT_CommentandCT_Commentsinwml.xsd, MS-OI29500 §2.1.313–2.1.316, python-docx and Apache POI.w:commentsholds any number ofw:commentand nothing else.w:commentholds block-level content (paragraphs, tables and the other block elements), any number of them. Attributes:w:id(whole number, required),w:author,w:date(ST_DateTime, optional) andw:initials(string, optional).w:annotationRefis an empty element inside the comment’s own text. It stands for the mark with the author’s initials and the comment’s number. If it is missing, a mark can be added at the start of the comment.w:commentRangeStart,w:commentRangeEndandw:commentReferencehave onlyw:id, matching the comment’sw:id. With both range elements, the comment covers that range. With neither, it is anchored where the reference is. With only one of them, the standard calls the document non-conformant.w:commentReferencenames can be ignored on loading. If several comments share an id, only one is loaded. A reference whose id matches no comment makes the document non-conformant. A reference inside comment content can be ignored.Divergence from spec
w:authorno author is associated, but the transitional schema marks ituse="required"(CT_TrackChange), and python-docx declares it asRequiredAttribute, writingw:author=""for a new comment (pydocx-oxml-comments.pylines 36–45, 101).w:initialsto at most nine characters andw:authorto at most 255 (MS-OI29500 §2.1.313 a, c).w:ins,w:del,w:moveFrom,w:moveTo,w:…Changeor custom XML revision elements should appear in comment content (§2.1.313 b).Z(UTC). Word stores the date in the user’s time zone and, on load, ignores theZand reads it as local time (§2.1.313 d).w:commentReferenceis the anchor (§2.1.314 a, §2.1.315 b). This differs from §17.13.4.5, which calls the lone-element case non-conformant.w:commentsandw:commentwithw:pandw:tblchildren only (pydocx-oxml-comments.pylines 18–125). Apache POI givesXWPFCommentthe id, author, initials and date, and body access for paragraphs and tables (poi-XWPFComment.javalines 362–422).The viewer reads each comment’s author, initials, date and plain text (
pages.jslines 141–153), shades the text betweenw:commentRangeStartandw:commentRangeEnd(lines 766–767, 830), and draws a balloon in a markup area to the right of the page at the height of the paragraph that holds thew:commentReference(lines 498–508, 909–911). It keeps at most 40 marks and 300 characters of text for each paragraph, and takes only the text of the comment (no tables or formatting). The Overview lists the four extension parts described below: reply parent, resolved state, durable id, UTC date, follow-up flag, extension URIs and the people part. The balloons in the page view do not nest replies.