Document.InsertSection(DocumentPosition) Method
Inserts a new section into the document’s Document.Sections collection at a specified position.
Namespace: DevExpress.XtraRichEdit.API.Native
Assembly: DevExpress.RichEdit.v24.2.Core.dll
NuGet Package: DevExpress.RichEdit.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
pos | DocumentPosition | A DocumentPosition object that specifies the position into which you can insert a new section. |
Returns
Type | Description |
---|---|
Section | A Section object that is the section in the document located before the newly inserted section. |
Remarks
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.
Example
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.OpenXml);
}
Related GitHub Examples
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.