CommentCollection class

CommentCollection class

Provides typed access to a collection of Comment nodes. To learn more, visit the Working with Comments documentation article.

Inheritance: CommentCollectionNodeCollection

Indexers

NameDescription
__getitem__(index)Retrieves a Comment at the given index.

Properties

NameDescription
countGets the number of nodes in the collection.
(Inherited from NodeCollection)

Methods

NameDescription
add(node)Adds a node to the end of the collection.
(Inherited from NodeCollection)
clear()Removes all nodes from this collection and from the document.
(Inherited from NodeCollection)
contains(node)Determines whether a node is in the collection.
(Inherited from NodeCollection)
index_of(node)Returns the zero-based index of the specified node.
(Inherited from NodeCollection)
insert(index, node)Inserts a node into the collection at the specified index.
(Inherited from NodeCollection)
remove(node)Removes the node from the collection and from the document.
(Inherited from NodeCollection)
remove_at(index)Removes the node at the specified index from the collection and from the document.
(Inherited from NodeCollection)
to_array()Copies all nodes from the collection to a new array of nodes.
(Inherited from NodeCollection)

Examples

Shows how to mark a comment as “done”.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)
builder.writeln("Helo world!")

# Insert a comment to point out an error.
comment = aw.Comment(doc, "John Doe", "J.D.", datetime.now())
comment.set_text("Fix the spelling error!")
doc.first_section.body.first_paragraph.append_child(comment)

# Comments have a "done" flag, which is set to "False" by default.
# If a comment suggests that we make a change within the document,
# we can apply the change, and then also set the "done" flag afterwards to indicate the correction.
self.assertFalse(comment.done)

doc.first_section.body.first_paragraph.runs[0].text = "Hello world!"
comment.done = True

# Comments that are "done" will differentiate themselves
# from ones that are not "done" with a faded text color.
comment = aw.Comment(doc, "John Doe", "J.D.", datetime.now())
comment.set_text("Add text to this paragraph.")
builder.current_paragraph.append_child(comment)

doc.save(ARTIFACTS_DIR + "Comment.done.docx")

See Also