Body

Body class

Represents a container for the main text of a section.

To learn more, visit the Aspose.Words Document Object Model (DOM) documentation article.

public class Body : Story

Constructors

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

Properties

NameDescription
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.
FirstParagraph { get; }Gets the first paragraph in the story.
HasChildNodes { get; }Returns true if this node has any child nodes.
override IsComposite { get; }Returns true as this node can have child nodes.
LastChild { get; }Gets the last child of the node.
LastParagraph { get; }Gets the last paragraph in the story.
NextSibling { get; }Gets the node immediately following this node.
override NodeType { get; }Returns Body.
Paragraphs { get; }Gets a collection of paragraphs that are immediate children of the story.
ParentNode { get; }Gets the immediate parent of this node.
ParentSection { get; }Gets the parent section of this story.
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.
StoryType { get; }Gets the type of this story.
Tables { get; }Gets a collection of tables that are immediate children of the story.

Methods

NameDescription
override Accept(DocumentVisitor)Accepts a visitor.
override AcceptEnd(DocumentVisitor)Accepts a visitor for visiting the end of the document’s body.
override AcceptStart(DocumentVisitor)Accepts a visitor for visiting the start of the document’s body.
AppendChild<T>(T)Adds the specified node to the end of the list of child nodes for this node.
AppendParagraph(string)A shortcut method that creates a Paragraph object with optional text and appends it to the end of this object.
Clone(bool)Creates a duplicate of the node.
CreateNavigator()Creates navigator which can be used to traverse and read nodes.
DeleteShapes()Deletes all shapes from the text of this story.
EnsureMinimum()If the last child is not a paragraph, creates and appends one empty paragraph.
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.
GetEnumerator()Provides support for the for each style iteration over the child nodes of this node.
override GetText()Gets the text of this node and of all its children.
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.
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

Body can contain Paragraph and Table child nodes.

Body is a section-level node and can only be a child of Section. There can only be one Body in a Section.

A minimal valid Body needs to contain at least one Paragraph.

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