Back to Devexpress

SubDocument.InsertDocumentContent(DocumentPosition, DocumentRange, InsertOptions) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-subdocument-dot-insertdocumentcontent-x28-documentposition-documentrange-insertoptions-x29.md

latest6.0 KB
Original Source

SubDocument.InsertDocumentContent(DocumentPosition, DocumentRange, InsertOptions) Method

Inserts content from the specified range in the current document at the specified position.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
DocumentRange InsertDocumentContent(
    DocumentPosition pos,
    DocumentRange range,
    InsertOptions insertOptions
)
vb
Function InsertDocumentContent(
    pos As DocumentPosition,
    range As DocumentRange,
    insertOptions As InsertOptions
) As DocumentRange

Parameters

NameTypeDescription
posDocumentPosition

A DocumentPosition specifying the position in the current document, after which content is inserted.

| | range | DocumentRange |

A DocumentRange representing the source range for insertion.

| | insertOptions | InsertOptions |

An InsertOptions enumeration value, specifying how destination formatting is applied to inserted content in certain cases.

|

Returns

TypeDescription
DocumentRange

A DocumentRange representing the document range with inserted content.

|

Remarks

The InsertDocumentContent method inserts the specified document range at the specified position of the main document.

Specify the insertOptions parameter to define how formatting is applied to the formatted text inserted into a document. Refer to the InsertOptions enumeration description for information on how formatting is applied to the pasted document elements depending on the property value.

The inserted text starts with a new paragraph and preserves formatting. It is inserted into an existing section and gets all section details (header, footer, page and print layout).

When the content being inserted is divided into sections, the inserted and destination sections interact as follows:

  • If the content is inserted into an empty document, all inserted section properties are retained.
  • If the content is inserted into a document divided into sections, all but the last inserted sections retain their parameters. The last section takes on the destination section’s options.
  • If the content is inserted after a section break, both destination and inserted sections retain their properties.

If the content is copied without section properties (the last section’s paragraph is not included), the destination section’s settings stay intact after insertion.

If the text being inserted contains document styles which are not present in the current document, the styles are copied to the resulting document.

If the document whose content is being inserted contains floating objects, such as pictures or text boxes, they are inserted into the corresponding positions in a newly created range. The Shape.Range property of a floating object determines whether it falls within the range being inserted and will therefore be added to the resulting document.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the InsertDocumentContent(DocumentPosition, DocumentRange, InsertOptions) 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.

word-processing-merge-documents-with-different-headers-and-footers/CS/Helpers/SectionsMerger.cs#L32

csharp
target.Delete(target.Range);
target.InsertDocumentContent(target.Range.Start, source.Range, InsertOptions.KeepSourceFormatting);

word-processing-merge-documents-with-different-headers-and-footers/VB/Helpers/SectionsMerger.vb#L31

vb
target.Delete(target.Range)
target.InsertDocumentContent(target.Range.Start, source.Range, InsertOptions.KeepSourceFormatting)
' Delete empty paragraphs

See Also

SubDocument Interface

SubDocument Members

DevExpress.XtraRichEdit.API.Native Namespace