Detailed Description

Represents a paragraph of text.

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 ControlChar.ParagraphBreak or end of cell ControlChar.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 node by node.

auto doc = MakeObject<Document>();
// A newly created blank document still comes one section, one body and one paragraph
// Calling this method will remove all those nodes to completely empty the document
doc->RemoveAllChildren();
// This document now has no composite nodes that content can be added to
// If we wish to edit it, we will need to repopulate its node collection,
// which we will start to do with by creating a new Section node
auto section = MakeObject<Section>(doc);
// Append the section to the document
doc->AppendChild(section);
// Lets set some properties for the section
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(PaperSize::Letter);
// The section that we created is empty, lets populate it. The section needs at least the Body node
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
// The body needs to have at least one paragraph
// Note that the paragraph has not yet been added to the document,
// but we have to specify the parent document
// The parent document is needed so the paragraph can correctly work
// with styles and other document-wide information
auto para = MakeObject<Paragraph>(doc);
body->AppendChild(para);
// We can set some formatting for the paragraph
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
// So far we have one empty paragraph in the document
// The document is valid and can be saved, but lets add some text before saving
// Create a new run of text and add it to our 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(String(u"Hello World!") + ControlChar::SectionBreakChar, doc->GetText());
doc->Save(ArtifactsDir + u"Section.CreateFromScratch.docx");

#include <Aspose.Words.Cpp/Model/Text/Paragraph.h>

+ Inheritance diagram for Aspose::Words::Paragraph:

Public Member Functions

 Paragraph (SharedPtr< DocumentBase > doc)
 Initializes a new instance of the Paragraph class. More...
 
bool Accept (SharedPtr< DocumentVisitor > visitor) override
 Accepts a visitor. More...
 
SharedPtr< FieldAppendField (FieldType fieldType, bool updateField)
 Appends a field to this paragraph. More...
 
SharedPtr< FieldAppendField (String fieldCode)
 Appends a field to this paragraph. More...
 
SharedPtr< FieldAppendField (String fieldCode, String fieldValue)
 Appends a field to this paragraph. More...
 
bool 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. More...
 
SharedPtr< FrameFormatget_FrameFormat ()
 Provides access to the paragraph formatting properties. More...
 
bool get_IsDeleteRevision ()
 Returns true if this object was deleted in Microsoft Word while change tracking was enabled. More...
 
bool get_IsEndOfCell ()
 True if this paragraph is the last paragraph in a Cell; false otherwise. More...
 
bool get_IsEndOfDocument ()
 True if this paragraph is the last paragraph in the last section of the document. More...
 
bool get_IsEndOfHeaderFooter ()
 True if this paragraph is the last paragraph in the HeaderFooter (main text story) of a Section; false otherwise. More...
 
bool get_IsEndOfSection ()
 True if this paragraph is the last paragraph in the Body (main text story) of a Section; false otherwise. More...
 
bool get_IsFormatRevision ()
 Returns true if formatting of the object was changed in Microsoft Word while change tracking was enabled. More...
 
bool get_IsInCell ()
 True if this paragraph is an immediate child of Cell; false otherwise. More...
 
bool get_IsInsertRevision ()
 Returns true if this object was inserted in Microsoft Word while change tracking was enabled. More...
 
bool get_IsListItem ()
 True when the paragraph is an item in a bulleted or numbered list in original revision. More...
 
bool get_IsMoveFromRevision ()
 Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled. More...
 
bool get_IsMoveToRevision ()
 Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled. More...
 
SharedPtr< ListFormatget_ListFormat ()
 Provides access to the list formatting properties of the paragraph. More...
 
SharedPtr< ListLabelget_ListLabel ()
 Gets a ListLabel object that provides access to list numbering value and formatting for this paragraph. More...
 
NodeType get_NodeType () const override
 Returns NodeType.Paragraph. More...
 
SharedPtr< Fontget_ParagraphBreakFont ()
 Provides access to the font formatting of the paragraph break character. More...
 
SharedPtr< ParagraphFormatget_ParagraphFormat ()
 Provides access to the paragraph formatting properties. More...
 
SharedPtr< Sectionget_ParentSection ()
 Retrieves the parent Section of the paragraph. More...
 
SharedPtr< Storyget_ParentStory ()
 Retrieves the parent section-level story that can be Body or HeaderFooter. More...
 
SharedPtr< RunCollectionget_Runs ()
 Provides access to the typed collection of pieces of text inside the paragraph. More...
 
ArrayPtr< SharedPtr< TabStop > > GetEffectiveTabStops ()
 Returns array of all tab stops applied to this paragraph, including applied indirectly by styles or lists. More...
 
String GetText () override
 Gets the text of this paragraph including the end of paragraph character. More...
 
virtual const TypeInfoGetType () const override
 
SharedPtr< FieldInsertField (FieldType fieldType, bool updateField, SharedPtr< Node > refNode, bool isAfter)
 Inserts a field into this paragraph. More...
 
SharedPtr< FieldInsertField (String fieldCode, SharedPtr< Node > refNode, bool isAfter)
 Inserts a field into this paragraph. More...
 
SharedPtr< FieldInsertField (String fieldCode, String fieldValue, SharedPtr< Node > refNode, bool isAfter)
 Inserts a field into this paragraph. More...
 
virtual bool Is (const TypeInfo &target) const override
 
int32_t JoinRunsWithSameFormatting ()
 Joins runs with the same formatting in the paragraph. More...
 
- Public Member Functions inherited from CompositeNode
SharedPtr< NodeAppendChild (SharedPtr< Node > newChild)
 Adds the specified node to the end of the list of child nodes for this node. More...
 
SharedPtr< NodeCollectionget_ChildNodes ()
 Gets all immediate child nodes of this node. More...
 
SharedPtr< CompositeNodeget_Container () override
 
int32_t get_Count ()
 Gets the number of immediate children of this node. More...
 
SharedPtr< Nodeget_FirstChild () const
 Gets the first child of the node. More...
 
bool get_HasChildNodes ()
 Returns true if this node has any child nodes. More...
 
bool get_IsComposite () override
 Returns true as this node can have child nodes. More...
 
SharedPtr< Nodeget_LastChild () const
 Gets the last child of the node. More...
 
SharedPtr< NodeGetChild (NodeType nodeType, int32_t index, bool isDeep)
 Returns an Nth child node that matches the specified type. More...
 
SharedPtr< NodeCollectionGetChildNodes (NodeType nodeType, bool isDeep)
 Returns a live collection of child nodes that match the specified type. More...
 
SharedPtr< NodeGetCurrentNode () override
 
SharedPtr< IEnumerator< SharedPtr< Node > > > GetEnumerator () override
 Provides support for the for each style iteration over the child nodes of this node. More...
 
SharedPtr< NodeGetNextMatchingNode (SharedPtr< Node > curNode) override
 
int32_t IndexOf (SharedPtr< Node > child)
 Returns the index of the specified child node in the child node array. More...
 
SharedPtr< NodeInsertAfter (SharedPtr< Node > newChild, SharedPtr< Node > refChild)
 Inserts the specified node immediately after the specified reference node. More...
 
SharedPtr< NodeInsertBefore (SharedPtr< Node > newChild, SharedPtr< Node > refChild)
 Inserts the specified node immediately before the specified reference node. More...
 
SharedPtr< NodePrependChild (SharedPtr< Node > newChild)
 Adds the specified node to the beginning of the list of child nodes for this node. More...
 
void RemoveAllChildren ()
 Removes all the child nodes of the current node. More...
 
SharedPtr< NodeRemoveChild (SharedPtr< Node > oldChild)
 Removes the specified child node. More...
 
void RemoveSmartTags ()
 Removes all SmartTag descendant nodes of the current node. More...
 
SharedPtr< NodeListSelectNodes (String xpath)
 Selects a list of nodes matching the XPath expression. More...
 
SharedPtr< NodeSelectSingleNode (String xpath)
 Selects the first Node that matches the XPath expression. More...
 
- Public Member Functions inherited from Node
SharedPtr< NodeClone (bool isCloneChildren)
 
virtual SharedPtr< DocumentBaseget_Document () const
 Gets the document to which this node belongs. More...
 
SharedPtr< Nodeget_NextSibling ()
 Gets the node immediately following this node. More...
 
SharedPtr< CompositeNodeget_ParentNode ()
 Gets the immediate parent of this node. More...
 
SharedPtr< Nodeget_PreviousSibling ()
 Gets the node immediately preceding this node. More...
 
SharedPtr< Rangeget_Range ()
 Returns a Range object that represents the portion of a document that is contained in this node. More...
 
SharedPtr< CompositeNodeGetAncestor (NodeType ancestorType)
 Gets the first ancestor of the specified NodeType. More...
 
template<typename T >
GetAncestorOf ()
 
SharedPtr< NodeNextPreOrder (SharedPtr< Node > rootNode)
 Gets next node according to the pre-order tree traversal algorithm. More...
 
SharedPtr< NodePreviousPreOrder (SharedPtr< Node > rootNode)
 Gets the previous node according to the pre-order tree traversal algorithm. More...
 
void Remove ()
 Removes itself from the parent. More...
 
String ToString (SaveFormat saveFormat)
 Exports the content of the node into a string in the specified format. More...
 
String ToString (SharedPtr< SaveOptions > saveOptions)
 Exports the content of the node into a string using the specified save options. More...
 
- Public Member Functions inherited from Object
ASPOSECPP_SHARED_API Object ()
 
ASPOSECPP_SHARED_API Object (Object const &x)
 
virtual ASPOSECPP_SHARED_API ~Object ()
 
virtual ASPOSECPP_SHARED_API bool Equals (ptr obj)
 
Detail::SmartPtrCounter * GetCounter ()
 
virtual ASPOSECPP_SHARED_API int GetHashCode () const
 
ASPOSECPP_SHARED_API void Lock ()
 
virtual ASPOSECPP_SHARED_API ptr MemberwiseClone () const
 
Objectoperator= (Object const &x)
 
bool ReferenceEquals (String const &str, std::nullptr_t)
 
bool ReferenceEquals (String const &str1, String const &str2)
 
int RemovedSharedRefs (int count)
 
virtual ASPOSECPP_SHARED_API void SetTemplateWeakPtr (unsigned int argument)
 
int SharedCount () const
 
ObjectSharedRefAdded ()
 
int SharedRefRemovedSafe ()
 
virtual ASPOSECPP_SHARED_API String ToString () const
 
ASPOSECPP_SHARED_API void Unlock ()
 
Detail::SmartPtrCounter * WeakRefAdded ()
 
void WeakRefRemoved ()
 
- Public Member Functions inherited from System::Collections::Generic::IEnumerable< System::SharedPtr< Aspose::Words::Node > >
EnumeratorBasedIterator< T, IEnumerator< T > > begin () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > cbegin () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > cend () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > end () noexcept
 
bool LINQ_All (std::function< bool(T)> predicate)
 
bool LINQ_Any ()
 
bool LINQ_Any (std::function< bool(T)> predicate)
 
SharedPtr< IEnumerable< ResultType > > LINQ_Cast ()
 
SharedPtr< IEnumerable< Result > > LINQ_Cast ()
 
bool LINQ_Contains (T value)
 
int LINQ_Count ()
 
int LINQ_Count (const Func< T, bool > &predicate)
 
LINQ_ElementAt (int index)
 
LINQ_First ()
 
LINQ_First (const Func< T, bool > &predicate)
 
LINQ_FirstOrDefault ()
 
LINQ_FirstOrDefault (std::function< bool(T)> predicate)
 
LINQ_Last ()
 
LINQ_LastOrDefault ()
 
SharedPtr< IEnumerable< ResultType > > LINQ_OfType ()
 
SharedPtr< IEnumerable< Result > > LINQ_OfType ()
 
SharedPtr< IEnumerable< Source > > LINQ_OrderBy (const Func< Source, Key > &keySelector)
 
SharedPtr< IEnumerable< T > > LINQ_OrderBy (const Func< T, Key > &keySelector)
 
SharedPtr< IEnumerable< Result > > LINQ_Select (const Func< Source, Result > &selector)
 
SharedPtr< IEnumerable< ResultType > > LINQ_Select (const Func< T, ResultType > &selector)
 
ArrayPtr< T > LINQ_ToArray ()
 
SharedPtr< List< T > > LINQ_ToList ()
 
SharedPtr< IEnumerable< T > > LINQ_Where (std::function< bool(T)> predicate)
 

Static Public Member Functions

static const TypeInfoType ()
 
- Static Public Member Functions inherited from CompositeNode
static const TypeInfoType ()
 
- Static Public Member Functions inherited from Node
static String NodeTypeToString (NodeType nodeType)
 A utility method that converts a node type enum value into a user friendly string. More...
 
static const TypeInfoType ()
 
- Static Public Member Functions inherited from Object
bool Equals (double const &objA, double const &objB)
 
bool Equals (float const &objA, float const &objB)
 
static std::enable_if<!IsSmartPtr< T1 >::value &&!IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static bool ReferenceEquals (ptr const &objA, ptr const &objB)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, std::nullptr_t)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, T const &objB)
 
static const TypeInfoType ()
 

Additional Inherited Members

- Public Types inherited from Object
typedef SmartPtr< Objectptr
 
typedef System::Details::SharedMembersType shared_members_type
 
- Public Types inherited from System::Collections::Generic::IEnumerable< System::SharedPtr< Aspose::Words::Node > >
typedef IEnumerator< T > IEnumeratorType
 
typedef T ValueType
 

Constructor & Destructor Documentation

◆ Paragraph()

Aspose::Words::Paragraph::Paragraph ( System::SharedPtr< Aspose::Words::DocumentBase doc)

Initializes a new instance of the Paragraph class.

When Paragraph is created, it belongs to the specified document, but is not yet part of the document and ParentNode is null.

To append Paragraph to the document use InsertAfter or InsertBefore on the story where you want the paragraph inserted.

Parameters
docThe owner document.
Examples

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

auto doc = MakeObject<Document>();
// A newly created blank document still comes one section, one body and one paragraph
// Calling this method will remove all those nodes to completely empty the document
doc->RemoveAllChildren();
// This document now has no composite nodes that content can be added to
// If we wish to edit it, we will need to repopulate its node collection,
// which we will start to do with by creating a new Section node
auto section = MakeObject<Section>(doc);
// Append the section to the document
doc->AppendChild(section);
// Lets set some properties for the section
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(PaperSize::Letter);
// The section that we created is empty, lets populate it. The section needs at least the Body node
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
// The body needs to have at least one paragraph
// Note that the paragraph has not yet been added to the document,
// but we have to specify the parent document
// The parent document is needed so the paragraph can correctly work
// with styles and other document-wide information
auto para = MakeObject<Paragraph>(doc);
body->AppendChild(para);
// We can set some formatting for the paragraph
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
// So far we have one empty paragraph in the document
// The document is valid and can be saved, but lets add some text before saving
// Create a new run of text and add it to our 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(String(u"Hello World!") + ControlChar::SectionBreakChar, doc->GetText());
doc->Save(ArtifactsDir + u"Section.CreateFromScratch.docx");

Member Function Documentation

◆ Accept()

bool Aspose::Words::Paragraph::Accept ( System::SharedPtr< Aspose::Words::DocumentVisitor visitor)
overridevirtual

Accepts a visitor.

Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.

For more info see the Visitor design pattern.

Parameters
visitorThe visitor that will visit the nodes.
Returns
True if all nodes were visited; false if DocumentVisitor stopped the operation before visiting all nodes.

Implements Aspose::Words::Node.

◆ AppendField() [1/3]

System::SharedPtr<Aspose::Words::Fields::Field> Aspose::Words::Paragraph::AppendField ( Aspose::Words::Fields::FieldType  fieldType,
bool  updateField 
)

Appends a field to this paragraph.

Parameters
fieldTypeThe type of the field to append.
updateFieldSpecifies whether to update the field immediately.
Returns
A Field object that represents the appended field.
Examples

Shows how to insert fields in different ways.

// Create a blank document and get its first paragraph
auto doc = MakeObject<Document>();
SharedPtr<Paragraph> para = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
// Choose a DATE field by FieldType, append it to the end of the paragraph and update it
para->AppendField(FieldType::FieldDate, true);
// Append a TIME field using a field code
para->AppendField(u" TIME \\@ \"HH:mm:ss\" ");
// Append a QUOTE field that will display a placeholder value until it is updated manually in Microsoft Word
// or programmatically with Document.UpdateFields() or Field.Update()
para->AppendField(u" QUOTE \"Real value\"", u"Placeholder value");
// We can choose a node in the paragraph and insert a field
// before or after that node instead of appending it to the end of a paragraph
para = doc->get_FirstSection()->get_Body()->AppendParagraph(u"");
auto run = MakeObject<Run>(doc);
run->set_Text(u" My Run. ");
para->AppendChild(run);
// Insert an AUTHOR field into the paragraph and place it before the run we created
doc->get_BuiltInDocumentProperties()->idx_get(u"Author")->set_Value(System::ObjectExt::Box<String>(u"John Doe"));
para->InsertField(FieldType::FieldAuthor, true, run, false);
// Insert another field designated by field code before the run
para->InsertField(u" QUOTE \"Real value\" ", run, false);
// Insert another field with a place holder value and place it after the run
para->InsertField(u" QUOTE \"Real value\"", u" Placeholder value. ", run, true);
doc->Save(ArtifactsDir + u"Paragraph.InsertField.docx");

◆ AppendField() [2/3]

System::SharedPtr<Aspose::Words::Fields::Field> Aspose::Words::Paragraph::AppendField ( System::String  fieldCode)

Appends a field to this paragraph.

Parameters
fieldCodeThe field code to append (without curly braces).
Returns
A Field object that represents the appended field.
Examples

Shows how to insert fields in different ways.

// Create a blank document and get its first paragraph
auto doc = MakeObject<Document>();
SharedPtr<Paragraph> para = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
// Choose a DATE field by FieldType, append it to the end of the paragraph and update it
para->AppendField(FieldType::FieldDate, true);
// Append a TIME field using a field code
para->AppendField(u" TIME \\@ \"HH:mm:ss\" ");
// Append a QUOTE field that will display a placeholder value until it is updated manually in Microsoft Word
// or programmatically with Document.UpdateFields() or Field.Update()
para->AppendField(u" QUOTE \"Real value\"", u"Placeholder value");
// We can choose a node in the paragraph and insert a field
// before or after that node instead of appending it to the end of a paragraph
para = doc->get_FirstSection()->get_Body()->AppendParagraph(u"");
auto run = MakeObject<Run>(doc);
run->set_Text(u" My Run. ");
para->AppendChild(run);
// Insert an AUTHOR field into the paragraph and place it before the run we created
doc->get_BuiltInDocumentProperties()->idx_get(u"Author")->set_Value(System::ObjectExt::Box<String>(u"John Doe"));
para->InsertField(FieldType::FieldAuthor, true, run, false);
// Insert another field designated by field code before the run
para->InsertField(u" QUOTE \"Real value\" ", run, false);
// Insert another field with a place holder value and place it after the run
para->InsertField(u" QUOTE \"Real value\"", u" Placeholder value. ", run, true);
doc->Save(ArtifactsDir + u"Paragraph.InsertField.docx");

◆ AppendField() [3/3]

System::SharedPtr<Aspose::Words::Fields::Field> Aspose::Words::Paragraph::AppendField ( System::String  fieldCode,
System::String  fieldValue 
)

Appends a field to this paragraph.

Parameters
fieldCodeThe field code to append (without curly braces).
fieldValueThe field value to append. Pass null for fields that do not have a value.
Returns
A Field object that represents the appended field.
Examples

Shows how to insert fields in different ways.

// Create a blank document and get its first paragraph
auto doc = MakeObject<Document>();
SharedPtr<Paragraph> para = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
// Choose a DATE field by FieldType, append it to the end of the paragraph and update it
para->AppendField(FieldType::FieldDate, true);
// Append a TIME field using a field code
para->AppendField(u" TIME \\@ \"HH:mm:ss\" ");
// Append a QUOTE field that will display a placeholder value until it is updated manually in Microsoft Word
// or programmatically with Document.UpdateFields() or Field.Update()
para->AppendField(u" QUOTE \"Real value\"", u"Placeholder value");
// We can choose a node in the paragraph and insert a field
// before or after that node instead of appending it to the end of a paragraph
para = doc->get_FirstSection()->get_Body()->AppendParagraph(u"");
auto run = MakeObject<Run>(doc);
run->set_Text(u" My Run. ");
para->AppendChild(run);
// Insert an AUTHOR field into the paragraph and place it before the run we created
doc->get_BuiltInDocumentProperties()->idx_get(u"Author")->set_Value(System::ObjectExt::Box<String>(u"John Doe"));
para->InsertField(FieldType::FieldAuthor, true, run, false);
// Insert another field designated by field code before the run
para->InsertField(u" QUOTE \"Real value\" ", run, false);
// Insert another field with a place holder value and place it after the run
para->InsertField(u" QUOTE \"Real value\"", u" Placeholder value. ", run, true);
doc->Save(ArtifactsDir + u"Paragraph.InsertField.docx");

◆ get_BreakIsStyleSeparator()

bool Aspose::Words::Paragraph::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.

Examples

Shows how to write text to the same line as a TOC heading and have it not show up in the TOC.

// Create a blank document and insert a table of contents field
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->InsertTableOfContents(u"\\o \\h \\z \\u");
builder->InsertBreak(BreakType::PageBreak);
// Insert a paragraph with a style that will be picked up as an entry in the TOC
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
// Both these strings are on the same line and same paragraph and will therefore show up on the same TOC entry
builder->Write(u"Heading 1. ");
builder->Write(u"Will appear in the TOC. ");
// Any text on a new line that does not have a heading style will not register as a TOC entry
// If we insert a style separator, we can write more text on the same line
// and use a different style without it showing up in the TOC
// If we use a heading type style afterwards, we can draw two TOC entries from one line of document text
builder->InsertStyleSeparator();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Quote);
builder->Write(u"Won't appear in the TOC. ");
// This flag is set to true for such paragraphs
ASSERT_TRUE(doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_BreakIsStyleSeparator());
// Update the TOC and save the document
doc->UpdateFields();
doc->Save(ArtifactsDir + u"Paragraph.BreakIsStyleSeparator.docx");

◆ get_FrameFormat()

System::SharedPtr<Aspose::Words::FrameFormat> Aspose::Words::Paragraph::get_FrameFormat ( )

Provides access to the paragraph formatting properties.

Examples

Shows how to get information about formatting properties of paragraphs that are frames.

auto doc = MakeObject<Document>(MyDir + u"Paragraph frame.docx");
SharedPtr<ParagraphCollection> paragraphs = doc->get_FirstSection()->get_Body()->get_Paragraphs();
for (auto paragraph : System::IterateOver(paragraphs->LINQ_OfType<SharedPtr<Paragraph>>()->LINQ_Where([](SharedPtr<Paragraph> p) { return p->get_FrameFormat()->get_IsFrame(); })))
{
System::Console::WriteLine(String(u"Width: ") + paragraph->get_FrameFormat()->get_Width());
System::Console::WriteLine(String(u"Height: ") + paragraph->get_FrameFormat()->get_Height());
System::Console::WriteLine(String(u"HeightRule: ") + System::ObjectExt::ToString(paragraph->get_FrameFormat()->get_HeightRule()));
System::Console::WriteLine(String(u"HorizontalAlignment: ") + System::ObjectExt::ToString(paragraph->get_FrameFormat()->get_HorizontalAlignment()));
System::Console::WriteLine(String(u"VerticalAlignment: ") + System::ObjectExt::ToString(paragraph->get_FrameFormat()->get_VerticalAlignment()));
System::Console::WriteLine(String(u"HorizontalPosition: ") + paragraph->get_FrameFormat()->get_HorizontalPosition());
System::Console::WriteLine(String(u"RelativeHorizontalPosition: ") + System::ObjectExt::ToString(paragraph->get_FrameFormat()->get_RelativeHorizontalPosition()));
System::Console::WriteLine(String(u"HorizontalDistanceFromText: ") + paragraph->get_FrameFormat()->get_HorizontalDistanceFromText());
System::Console::WriteLine(String(u"VerticalPosition: ") + paragraph->get_FrameFormat()->get_VerticalPosition());
System::Console::WriteLine(String(u"RelativeVerticalPosition: ") + System::ObjectExt::ToString(paragraph->get_FrameFormat()->get_RelativeVerticalPosition()));
System::Console::WriteLine(String(u"VerticalDistanceFromText: ") + paragraph->get_FrameFormat()->get_VerticalDistanceFromText());
}

◆ get_IsDeleteRevision()

bool Aspose::Words::Paragraph::get_IsDeleteRevision ( )

Returns true if this object was deleted in Microsoft Word while change tracking was enabled.

Examples

Shows how to work with revision paragraphs.

auto doc = MakeObject<Document>();
SharedPtr<Body> body = doc->get_FirstSection()->get_Body();
SharedPtr<Paragraph> para = body->get_FirstParagraph();
// Add text to the first paragraph, then add two more paragraphs
para->AppendChild(MakeObject<Run>(doc, u"Paragraph 1. "));
body->AppendParagraph(u"Paragraph 2. ");
body->AppendParagraph(u"Paragraph 3. ");
// We have three paragraphs, none of which registered as any type of revision
// If we add/remove any content in the document while tracking revisions,
// they will be displayed as such in the document and can be accepted/rejected
doc->StartTrackRevisions(u"John Doe", System::DateTime::get_Now());
// This paragraph is a revision and will have the according "IsInsertRevision" flag set
para = body->AppendParagraph(u"Paragraph 4. ");
ASSERT_TRUE(para->get_IsInsertRevision());
// Get the document's paragraph collection and remove a paragraph
SharedPtr<ParagraphCollection> paragraphs = body->get_Paragraphs();
ASSERT_EQ(4, paragraphs->get_Count());
para = paragraphs->idx_get(2);
para->Remove();
// Since we are tracking revisions, the paragraph still exists in the document, will have the "IsDeleteRevision" set
// and will be displayed as a revision in Microsoft Word, until we accept or reject all revisions
ASSERT_EQ(4, paragraphs->get_Count());
ASSERT_TRUE(para->get_IsDeleteRevision());
// The delete revision paragraph is removed once we accept changes
doc->AcceptAllRevisions();
ASSERT_EQ(3, paragraphs->get_Count());
ASSERT_TRUE(para->get_Count() == 0);

◆ get_IsEndOfCell()

bool Aspose::Words::Paragraph::get_IsEndOfCell ( )

True if this paragraph is the last paragraph in a Cell; false otherwise.

Examples

Shows how to set a table to stay together on the same page.

auto doc = MakeObject<Document>(MyDir + u"Table spanning two pages.docx");
auto table = System::DynamicCast<Table>(doc->GetChild(NodeType::Table, 0, true));
// Enabling KeepWithNext for every paragraph in the table except for the last ones in the last row
// will prevent the table from being split across pages
for (auto cell : System::IterateOver(table->GetChildNodes(NodeType::Cell, true)->LINQ_OfType<SharedPtr<Cell> >()))
{
for (auto para : System::IterateOver(cell->get_Paragraphs()->LINQ_OfType<SharedPtr<Paragraph> >()))
{
ASSERT_TRUE(para->get_IsInCell());
if (!(cell->get_ParentRow()->get_IsLastRow() && para->get_IsEndOfCell()))
{
para->get_ParagraphFormat()->set_KeepWithNext(true);
}
}
}
doc->Save(ArtifactsDir + u"Table.KeepTableTogether.docx");

◆ get_IsEndOfDocument()

bool Aspose::Words::Paragraph::get_IsEndOfDocument ( )

True if this paragraph is the last paragraph in the last section of the document.

Examples

Shows how to insert a paragraph into the document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Specify font formatting
SharedPtr<Font> font = builder->get_Font();
font->set_Size(16);
font->set_Bold(true);
font->set_Name(u"Arial");
font->set_Underline(Underline::Dash);
// Specify paragraph formatting
SharedPtr<ParagraphFormat> paragraphFormat = builder->get_ParagraphFormat();
paragraphFormat->set_FirstLineIndent(8);
paragraphFormat->set_Alignment(ParagraphAlignment::Justify);
paragraphFormat->set_AddSpaceBetweenFarEastAndAlpha(true);
paragraphFormat->set_AddSpaceBetweenFarEastAndDigit(true);
paragraphFormat->set_KeepTogether(true);
// Using Writeln() ends the paragraph after writing and makes a new one, while Write() stays on the same paragraph
builder->Writeln(u"A whole paragraph.");
// We can use this flag to ensure that we're at the end of the document
ASSERT_TRUE(builder->get_CurrentParagraph()->get_IsEndOfDocument());

◆ get_IsEndOfHeaderFooter()

bool Aspose::Words::Paragraph::get_IsEndOfHeaderFooter ( )

True if this paragraph is the last paragraph in the HeaderFooter (main text story) of a Section; false otherwise.

Examples

Creates a header and footer using the document object model and insert them into a section.

auto doc = MakeObject<Document>();
auto header = MakeObject<HeaderFooter>(doc, HeaderFooterType::HeaderPrimary);
doc->get_FirstSection()->get_HeadersFooters()->Add(header);
// Add a paragraph with text to the footer
SharedPtr<Paragraph> para = header->AppendParagraph(u"My header");
ASSERT_TRUE(header->get_IsHeader());
ASSERT_TRUE(para->get_IsEndOfHeaderFooter());
auto footer = MakeObject<HeaderFooter>(doc, HeaderFooterType::FooterPrimary);
doc->get_FirstSection()->get_HeadersFooters()->Add(footer);
// Add a paragraph with text to the footer
para = footer->AppendParagraph(u"My footer");
ASSERT_FALSE(footer->get_IsHeader());
ASSERT_TRUE(para->get_IsEndOfHeaderFooter());
ASPOSE_ASSERT_EQ(footer, para->get_ParentStory());
ASPOSE_ASSERT_EQ(footer->get_ParentSection(), para->get_ParentSection());
ASPOSE_ASSERT_EQ(footer->get_ParentSection(), header->get_ParentSection());
doc->Save(ArtifactsDir + u"HeaderFooter.HeaderFooterCreate.docx");

◆ get_IsEndOfSection()

bool Aspose::Words::Paragraph::get_IsEndOfSection ( )

True if this paragraph is the last paragraph in the Body (main text story) of a Section; false otherwise.

◆ get_IsFormatRevision()

bool Aspose::Words::Paragraph::get_IsFormatRevision ( )

Returns true if formatting of the object was changed in Microsoft Word while change tracking was enabled.

Examples

Shows how to get information about whether this object was formatted in Microsoft Word while change tracking was enabled

auto doc = MakeObject<Document>(MyDir + u"Format revision.docx");
// This paragraph's formatting was changed while revisions were being tracked
ASSERT_TRUE(doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_IsFormatRevision());

◆ get_IsInCell()

bool Aspose::Words::Paragraph::get_IsInCell ( )

True if this paragraph is an immediate child of Cell; false otherwise.

Examples

Shows how to set a table to stay together on the same page.

auto doc = MakeObject<Document>(MyDir + u"Table spanning two pages.docx");
auto table = System::DynamicCast<Table>(doc->GetChild(NodeType::Table, 0, true));
// Enabling KeepWithNext for every paragraph in the table except for the last ones in the last row
// will prevent the table from being split across pages
for (auto cell : System::IterateOver(table->GetChildNodes(NodeType::Cell, true)->LINQ_OfType<SharedPtr<Cell> >()))
{
for (auto para : System::IterateOver(cell->get_Paragraphs()->LINQ_OfType<SharedPtr<Paragraph> >()))
{
ASSERT_TRUE(para->get_IsInCell());
if (!(cell->get_ParentRow()->get_IsLastRow() && para->get_IsEndOfCell()))
{
para->get_ParagraphFormat()->set_KeepWithNext(true);
}
}
}
doc->Save(ArtifactsDir + u"Table.KeepTableTogether.docx");

◆ get_IsInsertRevision()

bool Aspose::Words::Paragraph::get_IsInsertRevision ( )

Returns true if this object was inserted in Microsoft Word while change tracking was enabled.

Examples

Shows how to work with revision paragraphs.

auto doc = MakeObject<Document>();
SharedPtr<Body> body = doc->get_FirstSection()->get_Body();
SharedPtr<Paragraph> para = body->get_FirstParagraph();
// Add text to the first paragraph, then add two more paragraphs
para->AppendChild(MakeObject<Run>(doc, u"Paragraph 1. "));
body->AppendParagraph(u"Paragraph 2. ");
body->AppendParagraph(u"Paragraph 3. ");
// We have three paragraphs, none of which registered as any type of revision
// If we add/remove any content in the document while tracking revisions,
// they will be displayed as such in the document and can be accepted/rejected
doc->StartTrackRevisions(u"John Doe", System::DateTime::get_Now());
// This paragraph is a revision and will have the according "IsInsertRevision" flag set
para = body->AppendParagraph(u"Paragraph 4. ");
ASSERT_TRUE(para->get_IsInsertRevision());
// Get the document's paragraph collection and remove a paragraph
SharedPtr<ParagraphCollection> paragraphs = body->get_Paragraphs();
ASSERT_EQ(4, paragraphs->get_Count());
para = paragraphs->idx_get(2);
para->Remove();
// Since we are tracking revisions, the paragraph still exists in the document, will have the "IsDeleteRevision" set
// and will be displayed as a revision in Microsoft Word, until we accept or reject all revisions
ASSERT_EQ(4, paragraphs->get_Count());
ASSERT_TRUE(para->get_IsDeleteRevision());
// The delete revision paragraph is removed once we accept changes
doc->AcceptAllRevisions();
ASSERT_EQ(3, paragraphs->get_Count());
ASSERT_TRUE(para->get_Count() == 0);

◆ get_IsListItem()

bool Aspose::Words::Paragraph::get_IsListItem ( )

True when the paragraph is an item in a bulleted or numbered list in original revision.

Examples

Shows how to start a numbered list, add a bulleted list inside it, then return to the numbered list.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Create an outline list for the headings
SharedPtr<List> outlineList = doc->get_Lists()->Add(ListTemplate::OutlineNumbers);
builder->get_ListFormat()->set_List(outlineList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"This is my Chapter 1");
// Create a numbered list
SharedPtr<List> numberedList = doc->get_Lists()->Add(ListTemplate::NumberDefault);
builder->get_ListFormat()->set_List(numberedList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->Writeln(u"Numbered list item 1.");
// Every paragraph that comprises a list will have this flag
ASSERT_TRUE(builder->get_CurrentParagraph()->get_IsListItem());
ASSERT_TRUE(builder->get_ParagraphFormat()->get_IsListItem());
// Create a bulleted list
SharedPtr<List> bulletedList = doc->get_Lists()->Add(ListTemplate::BulletDefault);
builder->get_ListFormat()->set_List(bulletedList);
builder->get_ParagraphFormat()->set_LeftIndent(72);
builder->Writeln(u"Bulleted list item 1.");
builder->Writeln(u"Bulleted list item 2.");
builder->get_ParagraphFormat()->ClearFormatting();
// Revert to the numbered list
builder->get_ListFormat()->set_List(numberedList);
builder->Writeln(u"Numbered list item 2.");
builder->Writeln(u"Numbered list item 3.");
// Revert to the outline list
builder->get_ListFormat()->set_List(outlineList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"This is my Chapter 2");
builder->get_ParagraphFormat()->ClearFormatting();
builder->get_Document()->Save(ArtifactsDir + u"Lists.NestedLists.docx");

◆ get_IsMoveFromRevision()

bool Aspose::Words::Paragraph::get_IsMoveFromRevision ( )

Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled.

Examples

Shows how to get paragraph that was moved (deleted/inserted) in Microsoft Word while change tracking was enabled.

auto doc = MakeObject<Document>(MyDir + u"Revisions.docx");
// There are two sets of move revisions in this document
// One moves a small part of a paragraph, while the other moves a whole paragraph
// Paragraph.IsMoveFromRevision/IsMoveToRevision will only be true if a whole paragraph is moved, as in the latter case
SharedPtr<ParagraphCollection> paragraphs = doc->get_FirstSection()->get_Body()->get_Paragraphs();
for (int i = 0; i < paragraphs->get_Count(); i++)
{
if (paragraphs->idx_get(i)->get_IsMoveFromRevision())
{
System::Console::WriteLine(u"The paragraph {0} has been moved (deleted).", i);
}
if (paragraphs->idx_get(i)->get_IsMoveToRevision())
{
System::Console::WriteLine(u"The paragraph {0} has been moved (inserted).", i);
}
}

◆ get_IsMoveToRevision()

bool Aspose::Words::Paragraph::get_IsMoveToRevision ( )

Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled.

Examples

Shows how to get paragraph that was moved (deleted/inserted) in Microsoft Word while change tracking was enabled.

auto doc = MakeObject<Document>(MyDir + u"Revisions.docx");
// There are two sets of move revisions in this document
// One moves a small part of a paragraph, while the other moves a whole paragraph
// Paragraph.IsMoveFromRevision/IsMoveToRevision will only be true if a whole paragraph is moved, as in the latter case
SharedPtr<ParagraphCollection> paragraphs = doc->get_FirstSection()->get_Body()->get_Paragraphs();
for (int i = 0; i < paragraphs->get_Count(); i++)
{
if (paragraphs->idx_get(i)->get_IsMoveFromRevision())
{
System::Console::WriteLine(u"The paragraph {0} has been moved (deleted).", i);
}
if (paragraphs->idx_get(i)->get_IsMoveToRevision())
{
System::Console::WriteLine(u"The paragraph {0} has been moved (inserted).", i);
}
}

◆ get_ListFormat()

System::SharedPtr<Aspose::Words::ListFormat> Aspose::Words::Paragraph::get_ListFormat ( )

Provides access to the list formatting properties of the paragraph.

Examples

Shows how to output all paragraphs in a document that are bulleted or numbered.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_ListFormat()->ApplyNumberDefault();
builder->Writeln(u"Numbered list item 1");
builder->Writeln(u"Numbered list item 2");
builder->Writeln(u"Numbered list item 3");
builder->get_ListFormat()->RemoveNumbers();
builder->get_ListFormat()->ApplyBulletDefault();
builder->Writeln(u"Bulleted list item 1");
builder->Writeln(u"Bulleted list item 2");
builder->Writeln(u"Bulleted list item 3");
builder->get_ListFormat()->RemoveNumbers();
SharedPtr<NodeCollection> paras = doc->GetChildNodes(NodeType::Paragraph, true);
for (auto para : System::IterateOver(paras->LINQ_OfType<SharedPtr<Paragraph>>()->LINQ_Where([](SharedPtr<Paragraph> p) { return p->get_ListFormat()->get_IsListItem(); })))
{
System::Console::WriteLine(String::Format(u"This paragraph belongs to list ID# {0}, number style \"{1}\"", para->get_ListFormat()->get_List()->get_ListId(), para->get_ListFormat()->get_ListLevel()->get_NumberStyle()));
System::Console::WriteLine(String::Format(u"\t\"{0}\"", para->GetText().Trim()));
}

◆ get_ListLabel()

System::SharedPtr<Aspose::Words::Lists::ListLabel> Aspose::Words::Paragraph::get_ListLabel ( )

Gets a ListLabel object that provides access to list numbering value and formatting for this paragraph.

Examples

Shows how to extract the label of each paragraph in a list as a value or a String.

auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
doc->UpdateListLabels();
SharedPtr<NodeCollection> paras = doc->GetChildNodes(NodeType::Paragraph, true);
// Find if we have the paragraph list. In our document our list uses plain arabic numbers,
// which start at three and ends at six
for (auto paragraph : System::IterateOver(paras->LINQ_OfType<SharedPtr<Paragraph>>()->LINQ_Where([](SharedPtr<Paragraph> p) { return p->get_ListFormat()->get_IsListItem(); })))
{
System::Console::WriteLine(String::Format(u"List item paragraph #{0}", paras->IndexOf(paragraph)));
// This is the text we get when actually getting when we output this node to text format
// The list labels are not included in this text output. Trim any paragraph formatting characters
String paragraphText = paragraph->ToString(SaveFormat::Text).Trim();
System::Console::WriteLine(String::Format(u"\tExported Text: {0}", paragraphText));
SharedPtr<ListLabel> label = paragraph->get_ListLabel();
// This gets the position of the paragraph in current level of the list. If we have a list with multiple level then this
// will tell us what position it is on that particular level
System::Console::WriteLine(String::Format(u"\tNumerical Id: {0}", label->get_LabelValue()));
// Combine them together to include the list label with the text in the output
System::Console::WriteLine(String::Format(u"\tList label combined with text: {0} {1}", label->get_LabelString(), paragraphText));
}

◆ get_NodeType()

Aspose::Words::NodeType Aspose::Words::Paragraph::get_NodeType ( ) const
overridevirtual

◆ get_ParagraphBreakFont()

System::SharedPtr<Aspose::Words::Font> Aspose::Words::Paragraph::get_ParagraphBreakFont ( )

Provides access to the font formatting of the paragraph break character.

◆ get_ParagraphFormat()

System::SharedPtr<Aspose::Words::ParagraphFormat> Aspose::Words::Paragraph::get_ParagraphFormat ( )

Provides access to the paragraph formatting properties.

Examples

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

auto doc = MakeObject<Document>();
// A newly created blank document still comes one section, one body and one paragraph
// Calling this method will remove all those nodes to completely empty the document
doc->RemoveAllChildren();
// This document now has no composite nodes that content can be added to
// If we wish to edit it, we will need to repopulate its node collection,
// which we will start to do with by creating a new Section node
auto section = MakeObject<Section>(doc);
// Append the section to the document
doc->AppendChild(section);
// Lets set some properties for the section
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(PaperSize::Letter);
// The section that we created is empty, lets populate it. The section needs at least the Body node
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
// The body needs to have at least one paragraph
// Note that the paragraph has not yet been added to the document,
// but we have to specify the parent document
// The parent document is needed so the paragraph can correctly work
// with styles and other document-wide information
auto para = MakeObject<Paragraph>(doc);
body->AppendChild(para);
// We can set some formatting for the paragraph
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
// So far we have one empty paragraph in the document
// The document is valid and can be saved, but lets add some text before saving
// Create a new run of text and add it to our 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(String(u"Hello World!") + ControlChar::SectionBreakChar, doc->GetText());
doc->Save(ArtifactsDir + u"Section.CreateFromScratch.docx");

◆ get_ParentSection()

System::SharedPtr<Aspose::Words::Section> Aspose::Words::Paragraph::get_ParentSection ( )

Retrieves the parent Section of the paragraph.

Examples

Creates a header and footer using the document object model and insert them into a section.

auto doc = MakeObject<Document>();
auto header = MakeObject<HeaderFooter>(doc, HeaderFooterType::HeaderPrimary);
doc->get_FirstSection()->get_HeadersFooters()->Add(header);
// Add a paragraph with text to the footer
SharedPtr<Paragraph> para = header->AppendParagraph(u"My header");
ASSERT_TRUE(header->get_IsHeader());
ASSERT_TRUE(para->get_IsEndOfHeaderFooter());
auto footer = MakeObject<HeaderFooter>(doc, HeaderFooterType::FooterPrimary);
doc->get_FirstSection()->get_HeadersFooters()->Add(footer);
// Add a paragraph with text to the footer
para = footer->AppendParagraph(u"My footer");
ASSERT_FALSE(footer->get_IsHeader());
ASSERT_TRUE(para->get_IsEndOfHeaderFooter());
ASPOSE_ASSERT_EQ(footer, para->get_ParentStory());
ASPOSE_ASSERT_EQ(footer->get_ParentSection(), para->get_ParentSection());
ASPOSE_ASSERT_EQ(footer->get_ParentSection(), header->get_ParentSection());
doc->Save(ArtifactsDir + u"HeaderFooter.HeaderFooterCreate.docx");

◆ get_ParentStory()

System::SharedPtr<Aspose::Words::Story> Aspose::Words::Paragraph::get_ParentStory ( )

Retrieves the parent section-level story that can be Body or HeaderFooter.

Examples

Creates a header and footer using the document object model and insert them into a section.

auto doc = MakeObject<Document>();
auto header = MakeObject<HeaderFooter>(doc, HeaderFooterType::HeaderPrimary);
doc->get_FirstSection()->get_HeadersFooters()->Add(header);
// Add a paragraph with text to the footer
SharedPtr<Paragraph> para = header->AppendParagraph(u"My header");
ASSERT_TRUE(header->get_IsHeader());
ASSERT_TRUE(para->get_IsEndOfHeaderFooter());
auto footer = MakeObject<HeaderFooter>(doc, HeaderFooterType::FooterPrimary);
doc->get_FirstSection()->get_HeadersFooters()->Add(footer);
// Add a paragraph with text to the footer
para = footer->AppendParagraph(u"My footer");
ASSERT_FALSE(footer->get_IsHeader());
ASSERT_TRUE(para->get_IsEndOfHeaderFooter());
ASPOSE_ASSERT_EQ(footer, para->get_ParentStory());
ASPOSE_ASSERT_EQ(footer->get_ParentSection(), para->get_ParentSection());
ASPOSE_ASSERT_EQ(footer->get_ParentSection(), header->get_ParentSection());
doc->Save(ArtifactsDir + u"HeaderFooter.HeaderFooterCreate.docx");

◆ get_Runs()

System::SharedPtr<Aspose::Words::RunCollection> Aspose::Words::Paragraph::get_Runs ( )

Provides access to the typed collection of pieces of text inside the paragraph.

Examples

Shows how to view revision-related properties of Inline nodes.

auto doc = MakeObject<Document>(MyDir + u"Revision runs.docx");
// This document has 6 revisions
ASSERT_EQ(6, doc->get_Revisions()->get_Count());
// The parent node of a revision is the run that the revision concerns, which is an Inline node
auto run = System::DynamicCast<Run>(doc->get_Revisions()->idx_get(0)->get_ParentNode());
// Get the parent paragraph
SharedPtr<Paragraph> firstParagraph = run->get_ParentParagraph();
SharedPtr<RunCollection> runs = firstParagraph->get_Runs();
ASSERT_EQ(6, runs->ToArray()->get_Length());
// The text in the run at index #2 was typed after revisions were tracked, so it will count as an insert revision
// The font was changed, so it will also be a format revision
ASSERT_TRUE(runs->idx_get(2)->get_IsInsertRevision());
ASSERT_TRUE(runs->idx_get(2)->get_IsFormatRevision());
// If one node was moved from one place to another while changes were tracked,
// the node will be placed at the departure location as a "move to revision",
// and a "move from revision" node will be left behind at the origin, in case we want to reject changes
// Highlighting text and dragging it to another place with the mouse and cut-and-pasting (but not copy-pasting) both count as "move revisions"
// The node with the "IsMoveToRevision" flag is the arrival of the move operation, and the node with the "IsMoveFromRevision" flag is the departure point
ASSERT_TRUE(runs->idx_get(1)->get_IsMoveToRevision());
ASSERT_TRUE(runs->idx_get(4)->get_IsMoveFromRevision());
// If an Inline node gets deleted while changes are being tracked, it will leave behind a node with the IsDeleteRevision flag set to true until changes are accepted
ASSERT_TRUE(runs->idx_get(5)->get_IsDeleteRevision());

◆ GetEffectiveTabStops()

System::ArrayPtr<System::SharedPtr<Aspose::Words::TabStop> > Aspose::Words::Paragraph::GetEffectiveTabStops ( )

Returns array of all tab stops applied to this paragraph, including applied indirectly by styles or lists.

Examples

Shows how to set custom tab stops.

auto doc = MakeObject<Document>();
SharedPtr<Paragraph> para = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
// If there are no tab stops in this collection, while we are in this paragraph
// the cursor will jump 36 points each time we press the Tab key in Microsoft Word
ASSERT_EQ(0, doc->get_FirstSection()->get_Body()->get_FirstParagraph()->GetEffectiveTabStops()->get_Length());
// We can add custom tab stops in Microsoft Word if we enable the ruler via the view tab
// Each unit on that ruler is two default tab stops, which is 72 points
// Those tab stops can be programmatically added to the paragraph like this
SharedPtr<ParagraphFormat> format = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat();
format->get_TabStops()->Add(72, TabAlignment::Left, TabLeader::Dots);
format->get_TabStops()->Add(216, TabAlignment::Center, TabLeader::Dashes);
format->get_TabStops()->Add(360, TabAlignment::Right, TabLeader::Line);
// These tab stops are added to this collection, and can also be seen by enabling the ruler mentioned above
ASSERT_EQ(3, para->GetEffectiveTabStops()->get_Length());
// Add a Run with tab characters that will snap the text to our TabStop positions and save the document
para->AppendChild(MakeObject<Run>(doc, u"\tTab 1\tTab 2\tTab 3"));
doc->Save(ArtifactsDir + u"Paragraph.TabStops.docx");

◆ GetText()

System::String Aspose::Words::Paragraph::GetText ( )
overridevirtual

Gets the text of this paragraph including the end of paragraph character.

The text of all child nodes is concatenated and the end of paragraph character is appended as follows:

The returned string includes all control and special characters as described in ControlChar.

Examples

Shows how to add, update and delete child nodes from a CompositeNode's child collection.

auto doc = MakeObject<Document>();
// An empty document has one paragraph by default
ASSERT_EQ(1, doc->get_FirstSection()->get_Body()->get_Paragraphs()->get_Count());
// A paragraph is a composite node because it can contain runs, which are another type of node
SharedPtr<Paragraph> paragraph = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
auto paragraphText = MakeObject<Run>(doc, u"Initial text. ");
paragraph->AppendChild(paragraphText);
// We will place these 3 children into the main text of our paragraph
auto run1 = MakeObject<Run>(doc, u"Run 1. ");
auto run2 = MakeObject<Run>(doc, u"Run 2. ");
auto run3 = MakeObject<Run>(doc, u"Run 3. ");
// We initialized them but not in our paragraph yet
ASSERT_EQ(u"Initial text.", paragraph->GetText().Trim());
// Insert run2 before initial paragraph text. This will be at the start of the paragraph
paragraph->InsertBefore(run2, paragraphText);
// Insert run3 after initial paragraph text. This will be at the end of the paragraph
paragraph->InsertAfter(run3, paragraphText);
// Insert run1 before every other child node. run2 was the start of the paragraph, now it will be run1
paragraph->PrependChild(run1);
ASSERT_EQ(u"Run 1. Run 2. Initial text. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(4, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());
// Access the child node collection and update/delete children
(System::DynamicCast<Run>(paragraph->GetChildNodes(NodeType::Run, true)->idx_get(1)))->set_Text(u"Updated run 2. ");
paragraph->GetChildNodes(NodeType::Run, true)->Remove(paragraphText);
ASSERT_EQ(u"Run 1. Updated run 2. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(3, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());

Reimplemented from Aspose::Words::CompositeNode.

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Paragraph::GetType ( ) const
overridevirtual

Reimplemented from Aspose::Words::CompositeNode.

◆ InsertField() [1/3]

System::SharedPtr<Aspose::Words::Fields::Field> Aspose::Words::Paragraph::InsertField ( Aspose::Words::Fields::FieldType  fieldType,
bool  updateField,
System::SharedPtr< Aspose::Words::Node refNode,
bool  isAfter 
)

Inserts a field into this paragraph.

Parameters
fieldTypeThe type of the field to insert.
updateFieldSpecifies whether to update the field immediately.
refNodeReference node inside this paragraph (if refNode is null, then appends to the end of the paragraph).
isAfterWhether to insert the field after or before reference node.
Returns
A Field object that represents the inserted field.
Examples

Shows how to insert fields in different ways.

// Create a blank document and get its first paragraph
auto doc = MakeObject<Document>();
SharedPtr<Paragraph> para = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
// Choose a DATE field by FieldType, append it to the end of the paragraph and update it
para->AppendField(FieldType::FieldDate, true);
// Append a TIME field using a field code
para->AppendField(u" TIME \\@ \"HH:mm:ss\" ");
// Append a QUOTE field that will display a placeholder value until it is updated manually in Microsoft Word
// or programmatically with Document.UpdateFields() or Field.Update()
para->AppendField(u" QUOTE \"Real value\"", u"Placeholder value");
// We can choose a node in the paragraph and insert a field
// before or after that node instead of appending it to the end of a paragraph
para = doc->get_FirstSection()->get_Body()->AppendParagraph(u"");
auto run = MakeObject<Run>(doc);
run->set_Text(u" My Run. ");
para->AppendChild(run);
// Insert an AUTHOR field into the paragraph and place it before the run we created
doc->get_BuiltInDocumentProperties()->idx_get(u"Author")->set_Value(System::ObjectExt::Box<String>(u"John Doe"));
para->InsertField(FieldType::FieldAuthor, true, run, false);
// Insert another field designated by field code before the run
para->InsertField(u" QUOTE \"Real value\" ", run, false);
// Insert another field with a place holder value and place it after the run
para->InsertField(u" QUOTE \"Real value\"", u" Placeholder value. ", run, true);
doc->Save(ArtifactsDir + u"Paragraph.InsertField.docx");

◆ InsertField() [2/3]

System::SharedPtr<Aspose::Words::Fields::Field> Aspose::Words::Paragraph::InsertField ( System::String  fieldCode,
System::SharedPtr< Aspose::Words::Node refNode,
bool  isAfter 
)

Inserts a field into this paragraph.

Parameters
fieldCodeThe field code to insert (without curly braces).
refNodeReference node inside this paragraph (if refNode is null, then appends to the end of the paragraph).
isAfterWhether to insert the field after or before reference node.
Returns
A Field object that represents the inserted field.
Examples

Shows how to insert fields in different ways.

// Create a blank document and get its first paragraph
auto doc = MakeObject<Document>();
SharedPtr<Paragraph> para = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
// Choose a DATE field by FieldType, append it to the end of the paragraph and update it
para->AppendField(FieldType::FieldDate, true);
// Append a TIME field using a field code
para->AppendField(u" TIME \\@ \"HH:mm:ss\" ");
// Append a QUOTE field that will display a placeholder value until it is updated manually in Microsoft Word
// or programmatically with Document.UpdateFields() or Field.Update()
para->AppendField(u" QUOTE \"Real value\"", u"Placeholder value");
// We can choose a node in the paragraph and insert a field
// before or after that node instead of appending it to the end of a paragraph
para = doc->get_FirstSection()->get_Body()->AppendParagraph(u"");
auto run = MakeObject<Run>(doc);
run->set_Text(u" My Run. ");
para->AppendChild(run);
// Insert an AUTHOR field into the paragraph and place it before the run we created
doc->get_BuiltInDocumentProperties()->idx_get(u"Author")->set_Value(System::ObjectExt::Box<String>(u"John Doe"));
para->InsertField(FieldType::FieldAuthor, true, run, false);
// Insert another field designated by field code before the run
para->InsertField(u" QUOTE \"Real value\" ", run, false);
// Insert another field with a place holder value and place it after the run
para->InsertField(u" QUOTE \"Real value\"", u" Placeholder value. ", run, true);
doc->Save(ArtifactsDir + u"Paragraph.InsertField.docx");

◆ InsertField() [3/3]

System::SharedPtr<Aspose::Words::Fields::Field> Aspose::Words::Paragraph::InsertField ( System::String  fieldCode,
System::String  fieldValue,
System::SharedPtr< Aspose::Words::Node refNode,
bool  isAfter 
)

Inserts a field into this paragraph.

Parameters
fieldCodeThe field code to insert (without curly braces).
fieldValueThe field value to insert. Pass null for fields that do not have a value.
refNodeReference node inside this paragraph (if refNode is null, then appends to the end of the paragraph).
isAfterWhether to insert the field after or before reference node.
Returns
A Field object that represents the inserted field.
Examples

Shows how to insert fields in different ways.

// Create a blank document and get its first paragraph
auto doc = MakeObject<Document>();
SharedPtr<Paragraph> para = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
// Choose a DATE field by FieldType, append it to the end of the paragraph and update it
para->AppendField(FieldType::FieldDate, true);
// Append a TIME field using a field code
para->AppendField(u" TIME \\@ \"HH:mm:ss\" ");
// Append a QUOTE field that will display a placeholder value until it is updated manually in Microsoft Word
// or programmatically with Document.UpdateFields() or Field.Update()
para->AppendField(u" QUOTE \"Real value\"", u"Placeholder value");
// We can choose a node in the paragraph and insert a field
// before or after that node instead of appending it to the end of a paragraph
para = doc->get_FirstSection()->get_Body()->AppendParagraph(u"");
auto run = MakeObject<Run>(doc);
run->set_Text(u" My Run. ");
para->AppendChild(run);
// Insert an AUTHOR field into the paragraph and place it before the run we created
doc->get_BuiltInDocumentProperties()->idx_get(u"Author")->set_Value(System::ObjectExt::Box<String>(u"John Doe"));
para->InsertField(FieldType::FieldAuthor, true, run, false);
// Insert another field designated by field code before the run
para->InsertField(u" QUOTE \"Real value\" ", run, false);
// Insert another field with a place holder value and place it after the run
para->InsertField(u" QUOTE \"Real value\"", u" Placeholder value. ", run, true);
doc->Save(ArtifactsDir + u"Paragraph.InsertField.docx");

◆ Is()

virtual bool Aspose::Words::Paragraph::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from Aspose::Words::CompositeNode.

◆ JoinRunsWithSameFormatting()

int32_t Aspose::Words::Paragraph::JoinRunsWithSameFormatting ( )

Joins runs with the same formatting in the paragraph.

Returns
Number of joins performed. When N adjacent runs are being joined they count as N - 1 joins.
Examples

Shows how to simplify paragraphs by merging superfluous runs.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a few small runs into the document
builder->Write(u"Run 1. ");
builder->Write(u"Run 2. ");
builder->Write(u"Run 3. ");
builder->Write(u"Run 4. ");
// The Paragraph may look like it's in once piece in Microsoft Word,
// but it is fragmented into several Runs, which leaves room for optimization
// A big run may be split into many smaller runs with the same formatting
// if we keep splitting up a piece of text while manually editing it in Microsoft Word
SharedPtr<Paragraph> para = builder->get_CurrentParagraph();
ASSERT_EQ(4, para->get_Runs()->get_Count());
// Change the style of the last run to something different from the first three
para->get_Runs()->idx_get(3)->get_Font()->set_StyleIdentifier(StyleIdentifier::Emphasis);
// We can run the JoinRunsWithSameFormatting() method to merge similar Runs
// This method also returns the number of joins that occured during the merge
// Two merges occured to combine Runs 1-3, while Run 4 was left out because it has an incompatible style
ASSERT_EQ(2, para->JoinRunsWithSameFormatting());
// The paragraph has been simplified to two runs
ASSERT_EQ(2, para->get_Runs()->get_Count());
ASSERT_EQ(u"Run 1. Run 2. Run 3. ", para->get_Runs()->idx_get(0)->get_Text());
ASSERT_EQ(u"Run 4. ", para->get_Runs()->idx_get(1)->get_Text());

◆ Type()

static const System::TypeInfo& Aspose::Words::Paragraph::Type ( )
static
String
static String ToString(const char_t *obj)
static constexpr char16_t SectionBreakChar
End of section character: (char)12 or "\f".
Definition: ControlChar.h:1253
@ PageBreak
Explicit page break.
static ASPOSECPP_SHARED_API DateTime get_Now()
@ Center
Centers the text around the tab stop.
@ Quote
@ Text
Saves the document in the plain text format.
static ASPOSECPP_SHARED_API void WriteLine()
@ Left
Left-aligns the text after the tab stop.
std::enable_if_t<!Details::IsIterable< Enumerable >::value, Details::EnumeratorAdapter< Enumerable, T > > IterateOver(System::SmartPtr< Enumerable > enumerable)
@ Letter
8.5 x 11 inches.
@ Heading1
The Heading 1 style.
@ Dashes
The leader line is made up from dashes.
@ NewPage
The section starts from a new page.
@ Line
The leader line is a single line.
@ Justify
Text is aligned to both left and right.
@ HeaderPrimary
Primary header, also used for odd numbered pages.
@ Dash
@ Emphasis
static ASPOSECPP_SHARED_API Color get_Blue()
static ASPOSECPP_SHARED_API Color get_Red()
@ Dots
The leader line is made up from dots.
@ FooterPrimary
Primary footer, also used for odd numbered pages.
@ Right
Right-aligns the text at the tab stop.
@ Normal
The Normal style.
@ Run
A run of text.
@ Paragraph
A paragraph of text. A Paragraph node is a container for inline level elements Run,...
@ Table
A Table object that represents a table in a Word document. A Table node can have Row nodes.
@ Any
Indicates all node types. Allows to select all children.
@ Cell
A cell of a table row. A Cell node can have Paragraph and Table nodes.
@ Center
Text is centered horizontally.