Section
Inheritance: java.lang.Object, com.aspose.words.Node, com.aspose.words.CompositeNode
public class Section extends CompositeNode
Represents a single section in a document.
To learn more, visit the Working with Sections documentation article.
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 Node.deepClone(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 Document.getSections() object.
To copy and insert just content of the section excluding the section break and section properties use appendContent(com.aspose.words.Section) and prependContent(com.aspose.words.Section) methods.
Constructors
Constructor | Description |
---|---|
Section(DocumentBase doc) | Initializes a new instance of the Section class. |
Methods
Method | Description |
---|---|
accept(DocumentVisitor visitor) | Accepts a visitor. |
appendChild(Node newChild) | Adds the specified node to the end of the list of child nodes for this node. |
appendContent(Section sourceSection) | Inserts a copy of content of the source section at the end of this section. |
clearContent() | Clears the section. |
clearHeadersFooters() | Clears the headers and footers of this section. |
clearSectionAttrs() | |
dd() | |
deepClone() | Creates a duplicate of this section. |
deepClone(boolean isCloneChildren) | Creates a duplicate of the node. |
deleteHeaderFooterShapes() | Deletes all shapes (drawing objects) from the headers and footers of this section. |
ensureMinimum() | Ensures that the section has getBody() with one Paragraph. |
equals(Object arg0) | |
fetchInheritedSectionAttr(int key) | |
fetchSectionAttr(int key) | |
getAncestor(int ancestorType) | |
getAncestor(Class ancestorType) | Gets the first ancestor of the specified object type. |
getBody() | Returns the Body child node of the section. |
getChild(int nodeType, int index, boolean isDeep) | |
getChildNodes() | Gets all immediate child nodes of this node. |
getChildNodes(int nodeType, boolean isDeep) | |
getClass() | |
getContainer() | |
getCount() | Gets the number of immediate children of this node. |
getCurrentNode() | |
getCustomNodeId() | Specifies custom node identifier. |
getDirectSectionAttr(int key) | |
getDocument() | Gets the document to which this node belongs. |
getFirstChild() | Gets the first child of the node. |
getHeadersFooters() | Provides access to the headers and footers nodes of the section. |
getLastChild() | Gets the last child of the node. |
getNextMatchingNode(Node curNode) | |
getNextSibling() | Gets the node immediately following this node. |
getNodeType() | Returns NodeType.SECTION. |
getPageSetup() | Returns an object that represents page setup and section properties. |
getParentNode() | Gets the immediate parent of this node. |
getPreviousSibling() | Gets the node immediately preceding this node. |
getProtectedForForms() | True if the section is protected for forms. |
getRange() | Returns a Range object that represents the portion of a document that is contained in this node. |
getText() | Gets the text of this node and of all its children. |
hasChildNodes() | Returns true if this node has any child nodes. |
hashCode() | |
indexOf(Node child) | Returns the index of the specified child node in the child node array. |
insertAfter(Node newChild, Node refChild) | Inserts the specified node immediately after the specified reference node. |
insertBefore(Node newChild, Node refChild) | Inserts the specified node immediately before the specified reference node. |
isComposite() | Returns true as this node can have child nodes. |
iterator() | Provides support for the for each style iteration over the child nodes of this node. |
nextPreOrder(Node rootNode) | Gets next node according to the pre-order tree traversal algorithm. |
nodeTypeToString(int nodeType) | |
notify() | |
notifyAll() | |
prependChild(Node newChild) | Adds the specified node to the beginning of the list of child nodes for this node. |
prependContent(Section sourceSection) | Inserts a copy of content of the source section at the beginning of this section. |
previousPreOrder(Node rootNode) | 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(Node oldChild) | Removes the specified child node. |
removeSmartTags() | Removes all SmartTag descendant nodes of the current node. |
selectNodes(String xpath) | Selects a list of nodes matching the XPath expression. |
selectSingleNode(String xpath) | Selects the first Node that matches the XPath expression. |
setCustomNodeId(int value) | Specifies custom node identifier. |
setProtectedForForms(boolean value) | True if the section is protected for forms. |
setSectionAttr(int key, Object value) | |
toString() | |
toString(SaveOptions saveOptions) | Exports the content of the node into a string using the specified save options. |
toString(int saveFormat) | |
wait() | |
wait(long arg0) | |
wait(long arg0, int arg1) |
Section(DocumentBase doc)
public Section(DocumentBase doc)
Initializes a new instance of the Section class.
When the section is created, it belongs to the specified document, but is not yet part of the document and Node.getParentNode() is null .
To include Section into a document use CompositeNode.insertAfter(com.aspose.words.Node, com.aspose.words.Node) and CompositeNode.insertBefore(com.aspose.words.Node, com.aspose.words.Node) methods of the Document OR NodeCollection.add(com.aspose.words.Node) and NodeCollection.insert(int, com.aspose.words.Node) methods of the Document.getSections() property.
Parameters:
Parameter | Type | Description |
---|---|---|
doc | DocumentBase | The owner document. |
accept(DocumentVisitor visitor)
public boolean accept(DocumentVisitor visitor)
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:
Parameter | Type | Description |
---|---|---|
visitor | DocumentVisitor | The visitor that will visit the nodes. |
Returns: boolean - True if all nodes were visited; false if DocumentVisitor stopped the operation before visiting all nodes. Calls DocumentVisitor.visitSectionStart(com.aspose.words.Section), then calls Node.accept(com.aspose.words.DocumentVisitor) for all child nodes of the section and calls DocumentVisitor.visitSectionEnd(com.aspose.words.Section) at the end.
appendChild(Node newChild)
public Node appendChild(Node newChild)
Adds the specified node to the end of the list of child nodes for this node.
If the newChild is already in the tree, it is first removed.
If the node being inserted was created from another document, you should use M:Aspose.Words.DocumentBase.ImportNode(Aspose.Words.Node,System.Boolean,Aspose.Words.ImportFormatMode) to import the node to the current document. The imported node can then be inserted into the current document.
Parameters:
Parameter | Type | Description |
---|---|---|
newChild | Node | The node to add. |
Returns: Node - The node added.
appendContent(Section sourceSection)
public void appendContent(Section sourceSection)
Inserts a copy of content of the source section at the end of this section.
Only content of getBody() of the source section is copied, page setup, headers and footers are not copied.
The nodes are automatically imported if the source section belongs to a different document.
No new section is created in the destination document.
Parameters:
Parameter | Type | Description |
---|---|---|
sourceSection | Section | The section to copy content from. |
clearContent()
public void clearContent()
Clears the section.
The text of getBody() is cleared, only one empty paragraph is left that represents the section break.
The text of all headers and footers is cleared, but HeaderFooter objects themselves are not removed.
clearHeadersFooters()
public void clearHeadersFooters()
Clears the headers and footers of this section.
The text of all headers and footers is cleared, but HeaderFooter objects themselves are not removed.
This makes headers and footers of this section linked to headers and footers of the previous section.
clearSectionAttrs()
public void clearSectionAttrs()
dd()
public void dd()
deepClone()
public Section deepClone()
Creates a duplicate of this section.
Returns: Section
deepClone(boolean isCloneChildren)
public Node deepClone(boolean isCloneChildren)
Creates a duplicate of the node.
This method serves as a copy constructor for nodes. The cloned node has no parent, but belongs to the same document as the original node.
This method always performs a deep copy of the node. The isCloneChildren parameter specifies whether to perform copy all child nodes as well.
Parameters:
Parameter | Type | Description |
---|---|---|
isCloneChildren | boolean | True to recursively clone the subtree under the specified node; false to clone only the node itself. |
Returns: Node - The cloned node.
deleteHeaderFooterShapes()
public void deleteHeaderFooterShapes()
Deletes all shapes (drawing objects) from the headers and footers of this section.
ensureMinimum()
public void ensureMinimum()
Ensures that the section has getBody() with one Paragraph.
equals(Object arg0)
public boolean equals(Object arg0)
Parameters:
Parameter | Type | Description |
---|---|---|
arg0 | java.lang.Object |
Returns: boolean
fetchInheritedSectionAttr(int key)
public Object fetchInheritedSectionAttr(int key)
Parameters:
Parameter | Type | Description |
---|---|---|
key | int |
Returns: java.lang.Object
fetchSectionAttr(int key)
public Object fetchSectionAttr(int key)
Parameters:
Parameter | Type | Description |
---|---|---|
key | int |
Returns: java.lang.Object
getAncestor(int ancestorType)
public CompositeNode getAncestor(int ancestorType)
Parameters:
Parameter | Type | Description |
---|---|---|
ancestorType | int |
Returns: CompositeNode
getAncestor(Class ancestorType)
public CompositeNode getAncestor(Class ancestorType)
Gets the first ancestor of the specified object type.
Parameters:
Parameter | Type | Description |
---|---|---|
ancestorType | java.lang.Class | The object type of the ancestor to retrieve. |
Returns: CompositeNode - The ancestor of the specified type or null if no ancestor of this type was found.
The ancestor type matches if it is equal to ancestorType or derived from ancestorType .
getBody()
public Body getBody()
Returns the Body child node of the section.
Body contains main text of the section.
Returns null if the section does not have a Body node among its children.
Returns: Body - The Body child node of the section.
getChild(int nodeType, int index, boolean isDeep)
public Node getChild(int nodeType, int index, boolean isDeep)
Parameters:
Parameter | Type | Description |
---|---|---|
nodeType | int | |
index | int | |
isDeep | boolean |
Returns: Node
getChildNodes()
public NodeCollection getChildNodes()
Gets all immediate child nodes of this node.
Note, getChildNodes() is equivalent to calling M:Aspose.Words.CompositeNode.GetChildNodes(Aspose.Words.NodeType,System.Boolean) with arguments ( NodeType.ANY, false ) and creates and returns a new collection every time it is accessed.
If there are no child nodes, this property returns an empty collection.
Returns: NodeCollection - All immediate child nodes of this node.
getChildNodes(int nodeType, boolean isDeep)
public NodeCollection getChildNodes(int nodeType, boolean isDeep)
Parameters:
Parameter | Type | Description |
---|---|---|
nodeType | int | |
isDeep | boolean |
Returns: NodeCollection
getClass()
public final native Class<?> getClass()
Returns: java.lang.Class>
getContainer()
public CompositeNode getContainer()
Returns: CompositeNode
getCount()
public int getCount()
Gets the number of immediate children of this node.
Returns: int - The number of immediate children of this node.
getCurrentNode()
public Node getCurrentNode()
Returns: Node
getCustomNodeId()
public int getCustomNodeId()
Specifies custom node identifier.
Default is zero.
This identifier can be set and used arbitrarily. For example, as a key to get external data.
Important note, specified value is not saved to an output file and exists only during the node lifetime.
Returns: int - The corresponding int value.
getDirectSectionAttr(int key)
public Object getDirectSectionAttr(int key)
Parameters:
Parameter | Type | Description |
---|---|---|
key | int |
Returns: java.lang.Object
getDocument()
public DocumentBase getDocument()
Gets the document to which this node belongs.
The node always belongs to a document even if it has just been created and not yet added to the tree, or if it has been removed from the tree.
Returns: DocumentBase - The document to which this node belongs.
getFirstChild()
public Node getFirstChild()
Gets the first child of the node. If there is no first child node, a null is returned.
Returns: Node - The first child of the node.
getHeadersFooters()
public HeaderFooterCollection getHeadersFooters()
Provides access to the headers and footers nodes of the section.
Returns: HeaderFooterCollection - The corresponding HeaderFooterCollection value.
getLastChild()
public Node getLastChild()
Gets the last child of the node. If there is no last child node, a null is returned.
Returns: Node - The last child of the node.
getNextMatchingNode(Node curNode)
public Node getNextMatchingNode(Node curNode)
Parameters:
Parameter | Type | Description |
---|---|---|
curNode | Node |
Returns: Node
getNextSibling()
public Node getNextSibling()
Gets the node immediately following this node. If there is no next node, a null is returned.
Returns: Node - The node immediately following this node.
getNodeType()
public int getNodeType()
Returns NodeType.SECTION.
Returns: int - {NodeType.SECTION. The returned value is one of NodeType constants.
getPageSetup()
public PageSetup getPageSetup()
Returns an object that represents page setup and section properties.
Returns: PageSetup - An object that represents page setup and section properties.
getParentNode()
public CompositeNode getParentNode()
Gets the immediate parent of this node.
If a node has just been created and not yet added to the tree, or if it has been removed from the tree, the parent is null .
Returns: CompositeNode - The immediate parent of this node.
getPreviousSibling()
public Node getPreviousSibling()
Gets the node immediately preceding this node. If there is no preceding node, a null is returned.
Returns: Node - The node immediately preceding this node.
getProtectedForForms()
public boolean getProtectedForForms()
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.
Returns: boolean - The corresponding boolean value.
getRange()
public Range getRange()
Returns a Range object that represents the portion of a document that is contained in this node.
Returns: Range - A Range object that represents the portion of a document that is contained in this node.
getText()
public String getText()
Gets the text of this node and of all its children.
The returned string includes all control and special characters as described in ControlChar.
Returns: java.lang.String
hasChildNodes()
public boolean hasChildNodes()
Returns true if this node has any child nodes.
Returns: boolean - { true if this node has any child nodes.
hashCode()
public native int hashCode()
Returns: int
indexOf(Node child)
public int indexOf(Node child)
Returns the index of the specified child node in the child node array. Returns -1 if the node is not found in the child nodes.
Parameters:
Parameter | Type | Description |
---|---|---|
child | Node |
Returns: int
insertAfter(Node newChild, Node refChild)
public Node insertAfter(Node newChild, Node refChild)
Inserts the specified node immediately after the specified reference node.
If refChild is null , inserts newChild at the beginning of the list of child nodes.
If the newChild is already in the tree, it is first removed.
If the node being inserted was created from another document, you should use M:Aspose.Words.DocumentBase.ImportNode(Aspose.Words.Node,System.Boolean,Aspose.Words.ImportFormatMode) to import the node to the current document. The imported node can then be inserted into the current document.
Parameters:
Parameter | Type | Description |
---|---|---|
newChild | Node | The Node to insert. |
refChild | Node | The Node that is the reference node. The newChild is placed after the refChild . |
Returns: Node - The inserted node.
insertBefore(Node newChild, Node refChild)
public Node insertBefore(Node newChild, Node refChild)
Inserts the specified node immediately before the specified reference node.
If refChild is null , inserts newChild at the end of the list of child nodes.
If the newChild is already in the tree, it is first removed.
If the node being inserted was created from another document, you should use M:Aspose.Words.DocumentBase.ImportNode(Aspose.Words.Node,System.Boolean,Aspose.Words.ImportFormatMode) to import the node to the current document. The imported node can then be inserted into the current document.
Parameters:
Parameter | Type | Description |
---|---|---|
newChild | Node | The Node to insert. |
refChild | Node | The Node that is the reference node. The newChild is placed before this node. |
Returns: Node - The inserted node.
isComposite()
public boolean isComposite()
Returns true as this node can have child nodes.
Returns: boolean - { true as this node can have child nodes.
iterator()
public Iterator iterator()
Provides support for the for each style iteration over the child nodes of this node.
Returns: java.util.Iterator
nextPreOrder(Node rootNode)
public Node nextPreOrder(Node rootNode)
Gets next node according to the pre-order tree traversal algorithm.
Parameters:
Parameter | Type | Description |
---|---|---|
rootNode | Node | The top node (limit) of traversal. |
Returns: Node - Next node in pre-order order. Null if reached the rootNode .
nodeTypeToString(int nodeType)
public static String nodeTypeToString(int nodeType)
Parameters:
Parameter | Type | Description |
---|---|---|
nodeType | int |
Returns: java.lang.String
notify()
public final native void notify()
notifyAll()
public final native void notifyAll()
prependChild(Node newChild)
public Node prependChild(Node newChild)
Adds the specified node to the beginning of the list of child nodes for this node.
If the newChild is already in the tree, it is first removed.
If the node being inserted was created from another document, you should use M:Aspose.Words.DocumentBase.ImportNode(Aspose.Words.Node,System.Boolean,Aspose.Words.ImportFormatMode) to import the node to the current document. The imported node can then be inserted into the current document.
Parameters:
Parameter | Type | Description |
---|---|---|
newChild | Node | The node to add. |
Returns: Node - The node added.
prependContent(Section sourceSection)
public void prependContent(Section sourceSection)
Inserts a copy of content of the source section at the beginning of this section.
Only content of getBody() of the source section is copied, page setup, headers and footers are not copied.
The nodes are automatically imported if the source section belongs to a different document.
No new section is created in the destination document.
Parameters:
Parameter | Type | Description |
---|---|---|
sourceSection | Section | The section to copy content from. |
previousPreOrder(Node rootNode)
public Node previousPreOrder(Node rootNode)
Gets the previous node according to the pre-order tree traversal algorithm.
Parameters:
Parameter | Type | Description |
---|---|---|
rootNode | Node | The top node (limit) of traversal. |
Returns: Node - Previous node in pre-order order. Null if reached the rootNode .
remove()
public void remove()
Removes itself from the parent.
removeAllChildren()
public void removeAllChildren()
Removes all the child nodes of the current node.
removeChild(Node oldChild)
public Node removeChild(Node oldChild)
Removes the specified child node.
The parent of oldChild is set to null after the node is removed.
Parameters:
Parameter | Type | Description |
---|---|---|
oldChild | Node | The node to remove. |
Returns: Node - The removed node.
removeSmartTags()
public void removeSmartTags()
Removes all SmartTag descendant nodes of the current node. This method does not remove the content of the smart tags.
selectNodes(String xpath)
public NodeList selectNodes(String xpath)
Selects a list of nodes matching the XPath expression.
Only expressions with element names are supported at the moment. Expressions that use attribute names are not supported.
Parameters:
Parameter | Type | Description |
---|---|---|
xpath | java.lang.String | The XPath expression. |
Returns: NodeList - A list of nodes matching the XPath query.
selectSingleNode(String xpath)
public Node selectSingleNode(String xpath)
Selects the first Node that matches the XPath expression.
Only expressions with element names are supported at the moment. Expressions that use attribute names are not supported.
Parameters:
Parameter | Type | Description |
---|---|---|
xpath | java.lang.String | The XPath expression. |
Returns: Node - The first Node that matches the XPath query or null if no matching node is found.
setCustomNodeId(int value)
public void setCustomNodeId(int value)
Specifies custom node identifier.
Default is zero.
This identifier can be set and used arbitrarily. For example, as a key to get external data.
Important note, specified value is not saved to an output file and exists only during the node lifetime.
Parameters:
Parameter | Type | Description |
---|---|---|
value | int | The corresponding int value. |
setProtectedForForms(boolean value)
public void setProtectedForForms(boolean value)
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.
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean | The corresponding boolean value. |
setSectionAttr(int key, Object value)
public void setSectionAttr(int key, Object value)
Parameters:
Parameter | Type | Description |
---|---|---|
key | int | |
value | java.lang.Object |
toString()
public String toString()
Returns: java.lang.String
toString(SaveOptions saveOptions)
public String toString(SaveOptions saveOptions)
Exports the content of the node into a string using the specified save options.
Parameters:
Parameter | Type | Description |
---|---|---|
saveOptions | SaveOptions | Specifies the options that control how the node is saved. |
Returns: java.lang.String - The content of the node in the specified format.
toString(int saveFormat)
public String toString(int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
saveFormat | int |
Returns: java.lang.String
wait()
public final void wait()
wait(long arg0)
public final native void wait(long arg0)
Parameters:
Parameter | Type | Description |
---|---|---|
arg0 | long |
wait(long arg0, int arg1)
public final void wait(long arg0, int arg1)
Parameters:
Parameter | Type | Description |
---|---|---|
arg0 | long | |
arg1 | int |