officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-document-dot-insertsection-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-x29.md
Inserts a new section into the document’s Document.Sections collection at a specified position.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
Section InsertSection(
DocumentPosition pos
)
Function InsertSection(
pos As DocumentPosition
) As Section
| Name | Type | Description |
|---|---|---|
| pos | DocumentPosition |
A DocumentPosition object that specifies the position into which you can insert a new section.
|
| Type | Description |
|---|---|
| Section |
A Section object that is the section in the document located before the newly inserted section.
|
When you create a new section, it is automatically linked to the previous section and content from that section’s header is automatically inserted into the second section header. Remove this content before inserting new content in the header. Call the SubDocument.Delete() method to clear the header.
The following code sample shows how to insert a continuous section break after the specified paragraph:
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using (var wordProcessor = new RichEditDocumentServer())
{
wordProcessor.LoadDocument(@"Documents//Alice.docx");
Document document = wordProcessor.Document;
var section = document.InsertSection(document.Paragraphs[4].Range.End);
// Retrieve the inserted section
var sectionPosition = document.CreatePosition(section.Range.End.ToInt() + 1);
Section insertedSection = document.GetSection(sectionPosition);
insertedSection.StartType = SectionStartType.Continuous;
wordProcessor.SaveDocument("Alice_formatted.docx", DocumentFormat.Docx);
}
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Using wordProcessor = New RichEditDocumentServer()
wordProcessor.LoadDocument("Documents//Alice.docx")
Dim document As Document = wordProcessor.Document
Dim section = document.InsertSection(document.Paragraphs(4).Range.End)
' Retrieve the inserted section
Dim sectionPosition = document.CreatePosition(section.Range.End.ToInt() + 1)
Dim insertedSection As Section = document.GetSection(sectionPosition)
insertedSection.StartType = SectionStartType.Continuous
wordProcessor.SaveDocument("Alice_formatted.docx", DocumentFormat.Docx)
End Using
The following code snippets (auto-collected from DevExpress Examples) contain references to the InsertSection(DocumentPosition) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-richedit-table-of-contents-practical-guide/CS/Form1.cs#L98
Document.EndUpdateCharacters(cp);
Document.InsertSection(field.Range.End);
field.Update();
winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/SearchAndReplace.cs#L13
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
document.InsertSection(document.Range.Start);
// Specify a regular expression that will find all six letter words.
wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/SearchAndReplaceActions.cs#L13
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
document.InsertSection(document.Range.Start);
// Specify a regular expression that will find all six letter words.
word-processing-table-of-contents-practical-guide/CS/Program.cs#L130
document.EndUpdateCharacters(cp);
document.InsertSection(field.Range.End);
field.Update();
winforms-richedit-table-of-contents-practical-guide/VB/Form1.vb#L90
Document.EndUpdateCharacters(cp)
Document.InsertSection(field.Range.End)
field.Update()
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/SearchAndReplace.vb#L12
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
document.InsertSection(document.Range.Start)
' Specify a regular expression that will find all six letter words.
wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/SearchAndReplaceActions.vb#L10
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
document.InsertSection(document.Range.Start)
' Specify a regular expression that will find all six letter words.
word-processing-table-of-contents-practical-guide/VB/Program.vb#L127
document.EndUpdateCharacters(cp)
document.InsertSection(field.Range.End)
field.Update()
See Also