Aspose::Words::Paragraph class
Paragraph class
Represents a paragraph of text. To learn more, visit the Working with Paragraphs documentation article.
class Paragraph : public CompositeNode,
public IParaAttrSource,
public IRunAttrSource,
public Revisions::ITrackableNode
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 document’s paragraph. |
| AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor for visiting the start of the document’s paragraph. |
| 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. |
| GetEffectiveTabStops() | Returns array of all tab stops applied to this paragraph, including applied indirectly by styles or lists. |
| GetText() override | Gets the text of this paragraph including the end of paragraph character. |
| 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. |
| JoinRunsWithSameFormatting() | Joins runs with the same formatting in the paragraph. |
| JoinRunsWithSameFormatting(const System::SharedPtr<Aspose::Words::JoinRunsOptions> &) | Joins runs with the same formatting in the paragraph. |
| Paragraph(const System::SharedPtr<Aspose::Words::DocumentBase> &) | Initializes a new instance of the Paragraph class. |
| 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_FrameFormat() | Provides access to the frame formatting properties. |
| 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_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_NodeType() const override | Returns Paragraph. |
| get_ParagraphBreakFont() | Provides access to the font formatting of the paragraph break character. |
| get_ParagraphFormat() | Provides access to the paragraph formatting properties. |
| get_ParentSection() | Retrieves the parent Section of the paragraph. |
| get_ParentStory() | Retrieves the parent section-level story that can be Body or HeaderFooter. |
| get_Runs() | Provides access to the typed collection of pieces of text inside the paragraph. |
| 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
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 = System::MakeObject<Aspose::Words::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 = System::MakeObject<Aspose::Words::Section>(doc);
doc->AppendChild<System::SharedPtr<Aspose::Words::Section>>(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 = System::MakeObject<Aspose::Words::Body>(doc);
section->AppendChild<System::SharedPtr<Aspose::Words::Body>>(body);
// Create a paragraph, set some formatting properties, and then append it as a child to the body.
auto para = System::MakeObject<Aspose::Words::Paragraph>(doc);
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
body->AppendChild<System::SharedPtr<Aspose::Words::Paragraph>>(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 = System::MakeObject<Aspose::Words::Run>(doc);
run->set_Text(u"Hello World!");
run->get_Font()->set_Color(System::Drawing::Color::get_Red());
para->AppendChild<System::SharedPtr<Aspose::Words::Run>>(run);
ASSERT_EQ(doc->GetText().Trim(), u"Hello World!");
doc->Save(get_ArtifactsDir() + u"Section.CreateManually.docx");
See Also
- Class CompositeNode
- Namespace Aspose::Words
- Library Aspose.Words for C++