Aspose::Words::Paragraph class

Paragraph class

Represents a paragraph of text. To learn more, visit the Working with Paragraphs documentation article.

class Paragraph : public Aspose::Words::CompositeNode,
                  public Aspose::Words::IParaAttrSource,
                  public Aspose::Words::IRunAttrSource,
                  public Aspose::Words::Revisions::ITrackableNode

Methods

MethodDescription
Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>) overrideAccepts a visitor.
AcceptEnd(System::SharedPtr<Aspose::Words::DocumentVisitor>) overrideAccepts a visitor for visiting the end of the document’s paragraph.
AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>) overrideAccepts a visitor for visiting the start of the document’s paragraph.
AppendChild(T)
AppendField(Aspose::Words::Fields::FieldType, bool)Appends a field to this paragraph.
AppendField(const System::String&)Appends a field to this paragraph.
AppendField(const System::String&, const System::String&)Appends a field to this paragraph.
Clone(bool)Creates a duplicate of the node.
get_BreakIsStyleSeparator()True if this paragraph break is a Style Separator. A style separator allows one paragraph to consist of parts that have different paragraph styles.
get_Count()Gets the number of immediate children of this node.
get_CustomNodeId() constSpecifies custom node identifier.
virtual get_Document() constGets the document to which this node belongs.
get_FirstChild() constGets the first child of the node.
get_FrameFormat()Provides access to the frame formatting properties.
get_HasChildNodes()Returns true if this node has any child nodes.
get_IsComposite() overrideReturns 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_IsEndOfCell()True if this paragraph is the last paragraph in a Cell; false otherwise.
get_IsEndOfDocument()True if this paragraph is the last paragraph in the last section of the document.
get_IsEndOfHeaderFooter()True if this paragraph is the last paragraph in the HeaderFooter (main text story) of a Section; false otherwise.
get_IsEndOfSection()True if this paragraph is the last paragraph in the Body (main text story) of a Section; false otherwise.
get_IsFormatRevision()Returns true if formatting of the object was changed in Microsoft Word while change tracking was enabled.
get_IsInCell()True if this paragraph is an immediate child of Cell; false otherwise.
get_IsInsertRevision()Returns true if this object was inserted in Microsoft Word while change tracking was enabled.
get_IsListItem()True when the paragraph is an item in a bulleted or numbered list in original revision.
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() constGets the last child of the node.
get_ListFormat()Provides access to the list formatting properties of the paragraph.
get_ListLabel()Gets a ListLabel object that provides access to list numbering value and formatting for this paragraph.
get_NextNode() const
get_NextSibling()Gets the node immediately following this node.
get_NodeType() const overrideReturns Paragraph.
get_ParagraphBreakFont()Provides access to the font formatting of the paragraph break character.
get_ParagraphFormat()Provides access to the paragraph formatting properties.
get_ParentNode()Gets the immediate parent of this node.
get_ParentSection()Retrieves the parent Section of the paragraph.
get_ParentStory()Retrieves the parent section-level story that can be Body or HeaderFooter.
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_Runs()Provides access to the typed collection of pieces of text inside the paragraph.
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.
GetEffectiveTabStops()Returns array of all tab stops applied to this paragraph, including applied indirectly by styles or lists.
GetEnumerator() overrideProvides support for the for each style iteration over the child nodes of this node.
GetText() overrideGets the text of this paragraph including the end of paragraph character.
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>&)
InsertField(Aspose::Words::Fields::FieldType, bool, const System::SharedPtr<Aspose::Words::Node>&, bool)Inserts a field into this paragraph.
InsertField(const System::String&, const System::SharedPtr<Aspose::Words::Node>&, bool)Inserts a field into this paragraph.
InsertField(const System::String&, const System::String&, const System::SharedPtr<Aspose::Words::Node>&, bool)Inserts a field into this paragraph.
Is(const System::TypeInfo&) const override
IsAncestorNode(const System::SharedPtr<Aspose::Words::Node>&)
JoinRunsWithSameFormatting()Joins runs with the same formatting in the paragraph.
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.
Paragraph(const System::SharedPtr<Aspose::Words::DocumentBase>&)Initializes a new instance of the Paragraph class.
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.
RemoveChild(T)
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_CustomNodeId(int32_t)Setter for Aspose::Words::Node::get_CustomNodeId.
set_NextNode(const System::SharedPtr<Aspose::Words::Node>&)
set_PrevNode(const System::SharedPtr<Aspose::Words::Node>&)
SetParent(const System::SharedPtr<Aspose::Words::Node>&)
SetTemplateWeakPtr(uint32_t) override
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

Paragraph is a block-level node and can be a child of classes derived from Story or InlineStory.

Paragraph can contain any number of inline-level nodes and bookmarks.

The complete list of child nodes that can occur inside a paragraph consists of BookmarkStart, BookmarkEnd, FieldStart, FieldSeparator, FieldEnd, FormField, Comment, Footnote, Run, SpecialChar, Shape, GroupShape, SmartTag.

A valid paragraph in Microsoft Word always ends with a paragraph break character and a minimal valid paragraph consists just of a paragraph break. The Paragraph class automatically appends the appropriate paragraph break character at the end and this character is not part of the child nodes of the Paragraph, therefore a Paragraph can be empty.

Do not include the end of paragraph ParagraphBreak or end of cell Cell characters inside the text of the paragraph as it might make the paragraph invalid when the document is opened in Microsoft Word.

Examples

Shows how to construct an Aspose.Words document by hand.

auto doc = MakeObject<Document>();

// A blank document contains one section, one body and one paragraph.
// Call the "RemoveAllChildren" method to remove all those nodes,
// and end up with a document node with no children.
doc->RemoveAllChildren();

// This document now has no composite child nodes that we can add content to.
// If we wish to edit it, we will need to repopulate its node collection.
// First, create a new section, and then append it as a child to the root document node.
auto section = MakeObject<Section>(doc);
doc->AppendChild(section);

// Set some page setup properties for the section.
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(PaperSize::Letter);

// A section needs a body, which will contain and display all its contents
// on the page between the section's header and footer.
auto body = MakeObject<Body>(doc);
section->AppendChild(body);

// Create a paragraph, set some formatting properties, and then append it as a child to the body.
auto para = MakeObject<Paragraph>(doc);

para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);

body->AppendChild(para);

// Finally, add some content to do the document. Create a run,
// set its appearance and contents, and then append it as a child to the paragraph.
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello World!");
run->get_Font()->set_Color(System::Drawing::Color::get_Red());
para->AppendChild(run);

ASSERT_EQ(u"Hello World!", doc->GetText().Trim());

doc->Save(ArtifactsDir + u"Section.CreateManually.docx");

See Also