Word Style Not Preserved When Replacing Placeholder with RichTextBox Content

0 Answers 5 Views
RichTextBox
Yan
Top achievements
Rank 1
Yan asked on 16 Oct 2025, 05:44 PM

We have an application that modifies Word documents using a template system. In our Word template, we use placeholders like #NOTES# to mark where dynamic content should be inserted.

In our app, we define the content for #NOTES# using a RichTextBox, which allows formatting such as bold, italic, and underline. When we replace the placeholder using:

editor.ReplaceText("#NOTES#", importedSections);

…the basic formatting is preserved correctly in the final Word document.

However, when we apply a style like Heading1 to the text in the RichTextBox, that style is not carried over to the final Word output. We are using the following code to handle the import:


var importer = new DocumentElementImporter(document, flowDocument, ConflictingStylesResolutionMode.UseTargetStyle);

Despite this, the style (e.g., Heading1) is not applied in the resulting document. Is there something we’re missing to ensure that styles like Heading1 are preserved during the import?

Any help or guidance would be greatly appreciated!

Thanks in advance.

No answers yet. Maybe you can help?

Tags
RichTextBox
Asked by
Yan
Top achievements
Rank 1
Share this question
or