SectionCollection Class |
Namespace: Aspose.Words
The SectionCollection type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | Count |
Gets the number of nodes in the collection.
(Inherited from NodeCollection.) |
![]() ![]() | Item |
Retrieves a section at the given index.
|
Name | Description | |
---|---|---|
![]() ![]() | Add |
Adds a node to the end of the collection.
(Inherited from NodeCollection.) |
![]() ![]() | Clear |
Removes all nodes from this collection and from the document.
(Inherited from NodeCollection.) |
![]() ![]() | Contains |
Determines whether a node is in the collection.
(Inherited from NodeCollection.) |
![]() | Equals | (Inherited from Object.) |
![]() | GetEnumerator | (Inherited from NodeCollection.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetType | (Inherited from Object.) |
![]() ![]() | IndexOf |
Returns the zero-based index of the specified node.
(Inherited from NodeCollection.) |
![]() ![]() | Insert |
Inserts a node into the collection at the specified index.
(Inherited from NodeCollection.) |
![]() ![]() | Remove |
Removes the node from the collection and from the document.
(Inherited from NodeCollection.) |
![]() ![]() | RemoveAt |
Removes the node at the specified index from the collection and from the document.
(Inherited from NodeCollection.) |
![]() | ToArray |
Copies all sections from the collection to a new array of sections.
|
![]() | ToString | (Inherited from Object.) |
A Microsoft Word document can contain multiple sections. To create a section in a Microsoft Word, select the Insert/Break command and select a break type. The break specifies whether section starts on a new page or on the same page.
Programmatically inserting and removing sections can be used to customize documents produced during mail merge. If a document needs to have different content or parts of the content depending on some criteria, then you can create a "master" document that contains multiple sections and delete some of the sections before or after mail merge.
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Write("Section 1"); builder.InsertBreak(BreakType.SectionBreakNewPage); builder.Write("Section 2"); // This shows what is in the document originally. The document has two sections Console.WriteLine(doc.GetText()); // Delete the first section from the document doc.Sections.RemoveAt(0); // Duplicate the last section and append the copy to the end of the document int lastSectionIdx = doc.Sections.Count - 1; Section newSection = doc.Sections[lastSectionIdx].Clone(); doc.Sections.Add(newSection); // Check what the document contains after we changed it Console.WriteLine(doc.GetText());