Aspose::Words::Comment class
Comment class
Represents a container for text of a comment. To learn more, visit the Working with Comments documentation article.
class Comment : public InlineStory,
public INodeWithAnnotationId,
public Revisions::IMoveTrackableNode
Methods
| Method | Description |
|---|---|
| Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor. |
| AcceptEnd(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor for visiting the end of the comment. |
| AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor for visiting the start of the comment. |
| AddReply(const System::String &, const System::String &, System::DateTime, const System::String &) | Adds a reply to this comment. |
| Comment(const System::SharedPtr<Aspose::Words::DocumentBase> &) | Initializes a new instance of the Comment class. |
| Comment(const System::SharedPtr<Aspose::Words::DocumentBase> &, const System::String &, const System::String &, System::DateTime) | Initializes a new instance of the Comment class. |
| RemoveAllReplies() | Removes all replies to this comment. |
| RemoveReply(const System::SharedPtr<Aspose::Words::Comment> &) | Removes the specified reply to this comment. |
| SetText(const System::String &) | This is a convenience method that allows to easily set text of the comment. |
| get_Ancestor() | Returns the parent Comment object. Returns null for top-level comments. |
| get_Author() const | Returns or sets the author name for a comment. |
| get_DateTime() const | Gets the date and time that the comment was made. |
| get_DateTimeUtc() | Gets the UTC date and time that the comment was made. |
| get_Done() const | Gets or sets flag indicating that the comment has been marked done. |
| get_Id() const | Gets or sets the comment identifier. |
| get_Initial() const | Returns or sets the initials of the user associated with a specific comment. |
| get_NodeType() const override | Returns Comment. |
| get_ParentId() const | Gets the parent comment ID. A value of -1 means the comment has no parent. |
| get_Replies() | Returns a collection of Comment objects that are immediate children of the specified comment. |
| get_StoryType() override | Returns Comments. |
| set_Author(const System::String &) | Sets the author name for a comment. |
| set_DateTime(System::DateTime) | Gets the date and time that the comment was made. |
| set_Done(bool) | Sets flag indicating that the comment has been marked done. |
| set_Id(int32_t) | Sets the comment identifier. |
| set_Initial(const System::String &) | Sets the initials of the user associated with a specific comment. |
| set_ParentId(int32_t) | Sets the parent comment ID. A value of -1 means the comment has no parent. |
| EnsureMinimum() | If the last child is not a paragraph, creates and appends one empty paragraph. |
| get_FirstParagraph() override | Gets the first paragraph in the story. |
| get_Font() | Provides access to the font formatting of the anchor character of this object. |
| get_IsDeleteRevision() | Returns true if this object was deleted in Microsoft Word while change tracking was enabled. |
| get_IsInsertRevision() | Returns true if this object was inserted in Microsoft Word while change tracking was enabled. |
| get_IsMoveFromRevision() | Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled. |
| get_IsMoveToRevision() | Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled. |
| get_LastParagraph() override | Gets the last paragraph in the story. |
| get_Paragraphs() override | Gets a collection of paragraphs that are immediate children of the story. |
| get_ParentParagraph() | Retrieves the parent Paragraph of this node. |
| get_StoryType() override | Returns the type of the story. |
| get_Tables() override | Gets a collection of tables that are immediate children of the story. |
| virtual AcceptEnd(System::SharedPtr<Aspose::Words::DocumentVisitor>) | When implemented in a derived class, calls the VisitXXXEnd method of the specified document visitor. |
| virtual AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>) | When implemented in a derived class, calls the VisitXXXStart method of the specified document visitor. |
| AppendChild(T) | Adds the specified node to the end of the list of child nodes for this node. |
| GetChild(Aspose::Words::NodeType, int32_t, bool) | Returns an Nth child node that matches the specified type. |
| GetChildNodes(Aspose::Words::NodeType, bool) | Returns a live collection of child nodes that match the specified type. |
| GetEnumerator() override | Provides support for the for each style iteration over the child nodes of this node. |
| GetText() override | Gets the text of this node and of all its children. |
| IndexOf(const System::SharedPtr<Aspose::Words::Node> &) | Returns the index of the specified child node in the child node array. |
| InsertAfter(T, const System::SharedPtr<Aspose::Words::Node> &) | Inserts the specified node immediately after the specified reference node. |
| InsertBefore(T, const System::SharedPtr<Aspose::Words::Node> &) | Inserts the specified node immediately before the specified reference node. |
| PrependChild(T) | Adds the specified node to the beginning of the list of child nodes for this node. |
| RemoveAllChildren() | Removes all the child nodes of the current node. |
| RemoveChild(T) | Removes the specified child node. |
| RemoveSmartTags() | Removes all SmartTag descendant nodes of the current node. |
| SelectNodes(const System::String &) | Selects a list of nodes matching the XPath expression. |
| SelectSingleNode(const System::String &) | Selects the first Node that matches the XPath expression. |
| get_Count() | Gets the number of immediate children of this node. |
| get_FirstChild() const | Gets the first child of the node. |
| get_HasChildNodes() | Returns true if this node has any child nodes. |
| get_IsComposite() override | Returns true as this node can have child nodes. |
| get_LastChild() const | Gets the last child of the node. |
| virtual Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>) | Accepts a visitor. |
| Clone(bool) | Creates a duplicate of the node. |
| GetAncestor(Aspose::Words::NodeType) | Gets the first ancestor of the specified NodeType. |
| virtual GetText() | Gets the text of this node and of all its children. |
| NextPreOrder(const System::SharedPtr<Aspose::Words::Node> &) | Gets next node according to the pre-order tree traversal algorithm. |
| static NodeTypeToString(Aspose::Words::NodeType) | A utility method that converts a node type enum value into a user friendly string. |
| PreviousPreOrder(const System::SharedPtr<Aspose::Words::Node> &) | Gets the previous node according to the pre-order tree traversal algorithm. |
| Remove() | Removes itself from the parent. |
| ToString(Aspose::Words::SaveFormat) | Exports the content of the node into a string in the specified format. |
| ToString(const System::SharedPtr<Aspose::Words::Saving::SaveOptions> &) | Exports the content of the node into a string using the specified save options. |
| get_CustomNodeId() const | Specifies custom node identifier. |
| virtual get_Document() const | Gets the document to which this node belongs. |
| virtual get_IsComposite() | Returns true if this node can contain other nodes. |
| get_NextSibling() | Gets the node immediately following this node. |
| virtual get_NodeType() const | Gets the type of this node. |
| get_ParentNode() | Gets the immediate parent of this node. |
| get_PreviousSibling() | Gets the node immediately preceding this node. |
| get_Range() | Returns a Range object that represents the portion of a document that is contained in this node. |
| set_CustomNodeId(int32_t) | Specifies custom node identifier. |
Remarks
A comment is an annotation which is anchored to a region of text or to a position in text. A comment can contain an arbitrary amount of block-level content.
If a Comment object occurs on its own, the comment is anchored to the position of the Comment object.
To anchor a comment to a region of text three objects are required: Comment, CommentRangeStart and CommentRangeEnd. All three objects need to share the same Id value.
Comment is an inline-level node and can only be a child of Paragraph.
Comment can contain Paragraph and Table child nodes.
Examples
Shows how to add a comment to a document, and then reply to it.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
auto comment = System::MakeObject<Aspose::Words::Comment>(doc, u"John Doe", u"J.D.", System::DateTime::get_Now());
comment->SetText(u"My comment.");
// Place the comment at a node in the document's body.
// This comment will show up at the location of its paragraph,
// outside the right-side margin of the page, and with a dotted line connecting it to its paragraph.
builder->get_CurrentParagraph()->AppendChild<System::SharedPtr<Aspose::Words::Comment>>(comment);
// Add a reply, which will show up under its parent comment.
comment->AddReply(u"Joe Bloggs", u"J.B.", System::DateTime::get_Now(), u"New reply");
// Comments and replies are both Comment nodes.
ASSERT_EQ(doc->GetChildNodes(NodeType::Comment, true)->get_Count(), 2);
// Comments that do not reply to other comments are "top-level". They have no ancestor comments.
ASSERT_TRUE(System::TestTools::IsNull(comment->get_Ancestor()));
// Replies have an ancestor top-level comment.
ASPOSE_ASSERT_EQ(comment->get_Replies()->idx_get(0)->get_Ancestor(), comment);
doc->Save(get_ArtifactsDir() + u"Comment.AddCommentWithReply.docx");
Shows how to add a comment to a paragraph.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
builder->Write(u"Hello world!");
auto comment = System::MakeObject<Aspose::Words::Comment>(doc, u"John Doe", u"JD", System::DateTime::get_Today());
builder->get_CurrentParagraph()->AppendChild<System::SharedPtr<Aspose::Words::Comment>>(comment);
builder->MoveTo(comment->AppendChild<System::SharedPtr<Aspose::Words::Paragraph>>(System::MakeObject<Aspose::Words::Paragraph>(doc)));
builder->Write(u"Comment text.");
ASSERT_EQ(comment->get_DateTime(), System::DateTime::get_Today());
// In Microsoft Word, we can right-click this comment in the document body to edit it, or reply to it.
doc->Save(get_ArtifactsDir() + u"InlineStory.AddComment.docx");
See Also
- Class InlineStory
- Namespace Aspose::Words
- Library Aspose.Words for C++