Paragraph

Paragraph class

Represents a paragraph of text.

To learn more, visit the Working with Paragraphs documentation article.

public class Paragraph : CompositeNode

Constructors

NameDescription
Paragraph(DocumentBase)Initializes a new instance of the Paragraph class.

Properties

NameDescription
BreakIsStyleSeparator { get; }True if this paragraph break is a Style Separator. A style separator allows one paragraph to consist of parts that have different paragraph styles.
Count { get; }Gets the number of immediate children of this node.
CustomNodeId { get; set; }Specifies custom node identifier.
virtual Document { get; }Gets the document to which this node belongs.
FirstChild { get; }Gets the first child of the node.
FrameFormat { get; }Provides access to the frame formatting properties.
HasChildNodes { get; }Returns true if this node has any child nodes.
override IsComposite { get; }Returns true as this node can have child nodes.
IsDeleteRevision { get; }Returns true if this object was deleted in Microsoft Word while change tracking was enabled.
IsEndOfCell { get; }True if this paragraph is the last paragraph in a Cell; false otherwise.
IsEndOfDocument { get; }True if this paragraph is the last paragraph in the last section of the document.
IsEndOfHeaderFooter { get; }True if this paragraph is the last paragraph in the HeaderFooter (main text story) of a Section; false otherwise.
IsEndOfSection { get; }True if this paragraph is the last paragraph in the Body (main text story) of a Section; false otherwise.
IsFormatRevision { get; }Returns true if formatting of the object was changed in Microsoft Word while change tracking was enabled.
IsInCell { get; }True if this paragraph is an immediate child of Cell; false otherwise.
IsInsertRevision { get; }Returns true if this object was inserted in Microsoft Word while change tracking was enabled.
IsListItem { get; }True when the paragraph is an item in a bulleted or numbered list in original revision.
IsMoveFromRevision { get; }Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled.
IsMoveToRevision { get; }Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled.
LastChild { get; }Gets the last child of the node.
ListFormat { get; }Provides access to the list formatting properties of the paragraph.
ListLabel { get; }Gets a ListLabel object that provides access to list numbering value and formatting for this paragraph.
NextSibling { get; }Gets the node immediately following this node.
override NodeType { get; }Returns Paragraph.
ParagraphBreakFont { get; }Provides access to the font formatting of the paragraph break character.
ParagraphFormat { get; }Provides access to the paragraph formatting properties.
ParentNode { get; }Gets the immediate parent of this node.
ParentSection { get; }Retrieves the parent Section of the paragraph.
ParentStory { get; }Retrieves the parent section-level story that can be Body or HeaderFooter.
PreviousSibling { get; }Gets the node immediately preceding this node.
Range { get; }Returns a Range object that represents the portion of a document that is contained in this node.
Runs { get; }Provides access to the typed collection of pieces of text inside the paragraph.

Methods

NameDescription
override Accept(DocumentVisitor)Accepts a visitor.
override AcceptEnd(DocumentVisitor)Accepts a visitor for visiting the end of the document’s paragraph.
override AcceptStart(DocumentVisitor)Accepts a visitor for visiting the start of the document’s paragraph.
AppendChild<T>(T)Adds the specified node to the end of the list of child nodes for this node.
AppendField(string)Appends a field to this paragraph.
AppendField(FieldType, bool)Appends a field to this paragraph.
AppendField(string, string)Appends a field to this paragraph.
Clone(bool)Creates a duplicate of the node.
CreateNavigator()Creates navigator which can be used to traverse and read nodes.
GetAncestor(NodeType)Gets the first ancestor of the specified NodeType.
GetAncestor(Type)Gets the first ancestor of the specified object type.
GetChild(NodeType, int, bool)Returns an Nth child node that matches the specified type.
GetChildNodes(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()Provides support for the for each style iteration over the child nodes of this node.
override GetText()Gets the text of this paragraph including the end of paragraph character.
IndexOf(Node)Returns the index of the specified child node in the child node array.
InsertAfter<T>(T, Node)Inserts the specified node immediately after the specified reference node.
InsertBefore<T>(T, Node)Inserts the specified node immediately before the specified reference node.
InsertField(string, Node, bool)Inserts a field into this paragraph.
InsertField(FieldType, bool, Node, bool)Inserts a field into this paragraph.
InsertField(string, string, Node, bool)Inserts a field into this paragraph.
JoinRunsWithSameFormatting()Joins runs with the same formatting in the paragraph.
NextPreOrder(Node)Gets next node according to the pre-order tree traversal algorithm.
PrependChild<T>(T)Adds the specified node to the beginning of the list of child nodes for this node.
PreviousPreOrder(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>(T)Removes the specified child node.
RemoveSmartTags()Removes all SmartTag descendant nodes of the current node.
SelectNodes(string)Selects a list of nodes matching the XPath expression.
SelectSingleNode(string)Selects the first Node that matches the XPath expression.
ToString(SaveFormat)Exports the content of the node into a string in the specified format.
ToString(SaveOptions)Exports the content of the node into a string using the specified save options.

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.

Document doc = new 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.
Section section = new Section(doc);
doc.AppendChild(section);

// Set some page setup properties for the section.
section.PageSetup.SectionStart = SectionStart.NewPage;
section.PageSetup.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.
Body body = new Body(doc);
section.AppendChild(body);

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

para.ParagraphFormat.StyleName = "Heading 1";
para.ParagraphFormat.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.
Run run = new Run(doc);
run.Text = "Hello World!";
run.Font.Color = Color.Red;
para.AppendChild(run);

Assert.AreEqual("Hello World!", doc.GetText().Trim());

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

See Also