Section Class
Represents a single section in a document.
Inheritance Hierarchy

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 17.6
Syntax
public class Section : CompositeNode

public class Section : CompositeNode

The Section type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleSection
Initializes a new instance of the Section class.
Top
Properties
  NameDescription
Public propertyCode exampleBody
Returns the Body child node of the section.
Public propertyCode exampleChildNodes
Gets all immediate child nodes of this node.
(Inherited from CompositeNode.)
Public propertyCount
Gets the number of immediate children of this node.
(Inherited from CompositeNode.)
Public propertyCode exampleDocument
Gets the document to which this node belongs.
(Inherited from Node.)
Public propertyCode exampleFirstChild
Gets the first child of the node.
(Inherited from CompositeNode.)
Public propertyCode exampleHasChildNodes
Returns true if this node has any child nodes.
(Inherited from CompositeNode.)
Public propertyCode exampleHeadersFooters
Provides access to the headers and footers nodes of the section.
Public propertyCode exampleIsComposite
Returns true as this node can have child nodes.
(Inherited from CompositeNode.)
Public propertyCode exampleLastChild
Gets the last child of the node.
(Inherited from CompositeNode.)
Public propertyCode exampleNextSibling
Gets the node immediately following this node.
(Inherited from Node.)
Public propertyCode exampleNodeType
Returns NodeType.Section.
(Overrides NodeNodeType.)
Public propertyCode examplePageSetup
Returns an object that represents page setup and section properties.
Public propertyCode exampleParentNode
Gets the immediate parent of this node.
(Inherited from Node.)
Public propertyCode examplePreviousSibling
Gets the node immediately preceding this node.
(Inherited from Node.)
Public propertyCode exampleProtectedForForms
True if the section is protected for forms. When a section is protected for forms, users can select and modify text only in form fields in Microsoft Word.
Public propertyCode exampleRange
Returns a Range object that represents the portion of a document that is contained in this node.
(Inherited from Node.)
Top
Methods
  NameDescription
Public methodAccept
Accepts a visitor.
(Overrides NodeAccept(DocumentVisitor).)
Protected methodAcceptChildren (Inherited from CompositeNode.)
Protected methodAcceptCore (Inherited from CompositeNode.)
Public methodCode exampleAppendChild
Adds the specified node to the end of the list of child nodes for this node.
(Inherited from CompositeNode.)
Public methodCode exampleAppendContent
Inserts a copy of content of the source section at the end of this section.
Public methodCode exampleClearContent
Clears the section.
Public methodCode exampleClearHeadersFooters
Clears the headers and footers of this section.
Public methodClearSectionAttrs
ISectionAttrSource
Public methodCode exampleClone
Creates a duplicate of this section.
Public methodCode exampleClone(Boolean)
Creates a duplicate of the node.
(Inherited from Node.)
Protected methodCoreRemoveSelfOnly (Inherited from CompositeNode.)
Public methodCreateNavigator
Reserved for system use. IXPathNavigable.
(Inherited from CompositeNode.)
Public methodCode exampleDeleteHeaderFooterShapes
Deletes all shapes (drawing objects) from the headers and footers of this section.
Public methodCode exampleEnsureMinimum
Ensures that the section has Body with one Paragraph.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetAncestor(Type)
Gets the first ancestor of the specified object type.
(Inherited from Node.)
Public methodCode exampleGetAncestor(NodeType)
Gets the first ancestor of the specified NodeType.
(Inherited from Node.)
Public methodCode exampleGetChild
Returns an Nth child node that matches the specified type.
(Inherited from CompositeNode.)
Public methodCode exampleGetChildNodes(NodeType, Boolean)
Returns a live collection of child nodes that match the specified type.
(Inherited from CompositeNode.)
Public methodGetChildNodes(NodeType, Boolean, Boolean) Obsolete.
Returns a collection of child nodes that match the specified type.
(Inherited from CompositeNode.)
Public methodCode exampleGetEnumerator
Provides support for the for each style iteration over the child nodes of this node.
(Inherited from CompositeNode.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodCode exampleGetText
Gets the text of this node and of all its children.
(Inherited from CompositeNode.)
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Public methodCode exampleIndexOf
Returns the index of the specified child node in the child node array.
(Inherited from CompositeNode.)
Public methodCode exampleInsertAfter
Inserts the specified node immediately after the specified reference node.
(Inherited from CompositeNode.)
Public methodInsertBefore
Inserts the specified node immediately before the specified reference node.
(Inherited from CompositeNode.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodCode exampleNextPreOrder
Gets next node according to the pre-order tree traversal algorithm.
(Inherited from Node.)
Public methodCode examplePrependChild
Adds the specified node to the beginning of the list of child nodes for this node.
(Inherited from CompositeNode.)
Public methodCode examplePrependContent
Inserts a copy of content of the source section at the beginning of this section.
Public methodPreviousPreOrder
Gets the previous node according to the pre-order tree traversal algorithm.
(Inherited from Node.)
Public methodCode exampleRemove
Removes itself from the parent.
(Inherited from Node.)
Public methodCode exampleRemoveAllChildren
Removes all the child nodes of the current node.
(Inherited from CompositeNode.)
Public methodCode exampleRemoveChild
Removes the specified child node.
(Inherited from CompositeNode.)
Public methodCode exampleRemoveSmartTags
Removes all SmartTag descendant nodes of the current node.
(Inherited from CompositeNode.)
Public methodCode exampleSelectNodes
Selects a list of nodes matching the XPath expression.
(Inherited from CompositeNode.)
Public methodCode exampleSelectSingleNode
Selects the first Node that matches the XPath expression.
(Inherited from CompositeNode.)
Public methodSetSectionAttr
ISectionAttrSource
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodCode exampleToString(SaveFormat)
Exports the content of the node into a string in the specified format.
(Inherited from Node.)
Public methodCode exampleToString(SaveOptions)
Exports the content of the node into a string using the specified save options.
(Inherited from Node.)
Public methodToTxt Obsolete.
Exports the content of the node into a string in plain text format.
(Inherited from Node.)
Top
Remarks

Section can have one Body and maximum one HeaderFooter of each HeaderFooterType. Body and HeaderFooter nodes can be in any order inside Section.

A minimal valid section needs to have Body with one Paragraph.

Each section has its own set of properties that specify page size, orientation, margins etc.

You can create a copy of a section using Clone(Boolean). The copy can be inserted into the same or different document.

To add, insert or remove a whole section including section break and section properties use methods of the Sections object.

To copy and insert just content of the section excluding the section break and section properties use AppendContent and PrependContent methods.

Examples
Creates a simple document from scratch using the Aspose.Words object model.
[C#]

// Create an "empty" document. Note that like in Microsoft Word, 
// the empty document has one section, body and one paragraph in it.
Document doc = new Document();

// This truly makes the document empty. No sections (not possible in Microsoft Word).
doc.RemoveAllChildren();

// Create a new section node. 
// Note that the section has not yet been added to the document, 
// but we have to specify the parent document.
Section section = new Section(doc);

// Append the section to the document.
doc.AppendChild(section);

// Lets set some properties for the section.
section.PageSetup.SectionStart = SectionStart.NewPage;
section.PageSetup.PaperSize = PaperSize.Letter;


// The section that we created is empty, lets populate it. The section needs at least the Body node.
Body body = new 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.
Paragraph para = new Paragraph(doc);
body.AppendChild(para);

// We can set some formatting for the paragraph
para.ParagraphFormat.StyleName = "Heading 1";
para.ParagraphFormat.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.
Run run = new Run(doc);
run.Text = "Hello World!";
run.Font.Color = System.Drawing.Color.Red;
para.AppendChild(run);


// As a matter of interest, you can retrieve text of the whole document and
// see that \x000c is automatically appended. \x000c is the end of section character.
Console.WriteLine("Hello World!\x000c", doc.GetText());

// Save the document.
doc.Save(MyDir + "Section.CreateFromScratch Out.doc");
[Visual Basic]

' Create an "empty" document. Note that like in Microsoft Word, 
' the empty document has one section, body and one paragraph in it.
Dim doc As New Document()

' This truly makes the document empty. No sections (not possible in Microsoft Word).
doc.RemoveAllChildren()

' Create a new section node. 
' Note that the section has not yet been added to the document, 
' but we have to specify the parent document.
Dim section As New Section(doc)

' Append the section to the document.
doc.AppendChild(section)

' Lets set some properties for the section.
section.PageSetup.SectionStart = SectionStart.NewPage
section.PageSetup.PaperSize = PaperSize.Letter


' The section that we created is empty, lets populate it. The section needs at least the Body node.
Dim body As New 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.
Dim para As New Paragraph(doc)
body.AppendChild(para)

' We can set some formatting for the paragraph
para.ParagraphFormat.StyleName = "Heading 1"
para.ParagraphFormat.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.
Dim run As New Run(doc)
run.Text = "Hello World!"
run.Font.Color = System.Drawing.Color.Red
para.AppendChild(run)


' As a matter of interest, you can retrieve text of the whole document and
' see that \x000c is automatically appended. \x000c is the end of section character.
Console.WriteLine("Hello World!" & Constants.vbFormFeed, doc.GetText())

' Save the document.
doc.Save(MyDir & "Section.CreateFromScratch Out.doc")
See Also