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 Aspose::Words::InlineStory,
public Aspose::Words::INodeWithAnnotationId,
public Aspose::Words::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. |
AppendChild(T) | |
Clone(bool) | Creates a duplicate of the node. |
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. |
EnsureMinimum() | If the last child is not a paragraph, creates and appends one empty paragraph. |
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_Count() | Gets the number of immediate children of this node. |
get_CustomNodeId() const | Specifies custom node identifier. |
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. |
virtual get_Document() const | Gets the document to which this node belongs. |
get_Done() const | Gets or sets flag indicating that the comment has been marked done. |
get_FirstChild() const | Gets the first child of the node. |
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_HasChildNodes() | Returns true if this node has any child nodes. |
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_IsComposite() override | Returns true as this node can have child nodes. |
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_LastChild() const | Gets the last child of the node. |
get_LastParagraph() override | Gets the last paragraph in the story. |
get_NextNode() const | |
get_NextSibling() | Gets the node immediately following this node. |
get_NodeType() const override | Returns Comment. |
get_Paragraphs() override | Gets a collection of paragraphs that are immediate children of the story. |
get_ParentId() const | Gets the parent comment ID. A value of %-1 means the comment has no parent. |
get_ParentNode() | Gets the immediate parent of this node. |
get_ParentParagraph() | Retrieves the parent Paragraph of this node. |
get_PreviousSibling() | Gets the node immediately preceding this node. |
get_PrevNode() const | |
get_Range() | Returns a Range object that represents the portion of a document that is contained in this node. |
get_Replies() | Returns a collection of Comment objects that are immediate children of the specified comment. |
get_StoryType() override | Returns Comments. |
get_Tables() override | Gets a collection of tables that are immediate children of the story. |
GetAncestor(Aspose::Words::NodeType) | Gets the first ancestor of the specified NodeType. |
GetAncestorOf() | |
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. |
GetType() const override | |
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>&) | |
InsertBefore(T, const System::SharedPtr<Aspose::Words::Node>&) | |
Is(const System::TypeInfo&) const override | |
IsAncestorNode(const System::SharedPtr<Aspose::Words::Node>&) | |
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. |
PrependChild(T) | |
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. |
RemoveAllChildren() | Removes all the child nodes of the current node. |
RemoveAllReplies() | Removes all replies to this comment. |
RemoveChild(T) | |
RemoveReply(const System::SharedPtr<Aspose::Words::Comment>&) | Removes the specified reply to this comment. |
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. |
set_Author(const System::String&) | Setter for Aspose::Words::Comment::get_Author. |
set_CustomNodeId(int32_t) | Setter for Aspose::Words::Node::get_CustomNodeId. |
set_DateTime(System::DateTime) | Setter for Aspose::Words::Comment::get_DateTime. |
set_Done(bool) | Setter for Aspose::Words::Comment::get_Done. |
set_Id(int32_t) | Setter for Aspose::Words::Comment::get_Id. |
set_Initial(const System::String&) | Setter for Aspose::Words::Comment::get_Initial. |
set_NextNode(const System::SharedPtr<Aspose::Words::Node>&) | |
set_ParentId(int32_t) | Sets the parent comment ID. A value of %-1 means the comment has no parent. |
set_PrevNode(const System::SharedPtr<Aspose::Words::Node>&) | |
SetParent(const System::SharedPtr<Aspose::Words::Node>&) | |
SetTemplateWeakPtr(uint32_t) override | |
SetText(const System::String&) | This is a convenience method that allows to easily set text of the comment. |
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. |
static Type() |
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 = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto comment = MakeObject<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(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(2, doc->GetChildNodes(NodeType::Comment, true)->get_Count());
// Comments that do not reply to other comments are "top-level". They have no ancestor comments.
ASSERT_TRUE(comment->get_Ancestor() == nullptr);
// Replies have an ancestor top-level comment.
ASPOSE_ASSERT_EQ(comment, comment->get_Replies()->idx_get(0)->get_Ancestor());
doc->Save(ArtifactsDir + u"Comment.AddCommentWithReply.docx");
Shows how to add a comment to a paragraph.
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Write(u"Hello world!");
auto comment = MakeObject<Comment>(doc, u"John Doe", u"JD", System::DateTime::get_Today());
builder->get_CurrentParagraph()->AppendChild(comment);
builder->MoveTo(comment->AppendChild(MakeObject<Paragraph>(doc)));
builder->Write(u"Comment text.");
ASSERT_EQ(System::DateTime::get_Today(), comment->get_DateTime());
// In Microsoft Word, we can right-click this comment in the document body to edit it, or reply to it.
doc->Save(ArtifactsDir + u"InlineStory.AddComment.docx");
See Also
- Class InlineStory
- Namespace Aspose::Words
- Library Aspose.Words for C++