Copy from MS Word and Paste to Editor

The formatting toolbar gives you an option to paste copied text from MS Word documents. Special algorithms replicate the formatting style of MS Word and at the same time ensure that the HTML code produced is clean and easy to read and manage. The screenshot below shows source MS Word content that will be pasted into the editor. As you can see, it contains images, various fonts, font formatting, lists:

Word content

The button pointed by the arrow in the image below is used for this feature. Simply copy the text from any MS Word document and press the button in the WPF Editor. It will paste the content into the Editor preserving the formatting style of MS Word.

Content pasted from Word

Below is the HTML code for the above content. You can see that the HTML code is clean and easy to read.

HTML pasted from Word

To enable this programmatically, you can use the following code snippet.

C#

private void button1_click(object sender, RoutedEventArgs e)
{
    htmlEditor1.ToolbarItemOverrider.OnPasteFromMSWordButtonClicked(sender, e);
}

VB.NET

Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    htmlEditor1.ToolbarItemOverrider.OnPasteFromMsWordButtonClicked(sender, e)
End Sub

You no longer have to click the [W] button: AutoDetectWordPaste

The dedicated "Paste from MS Word" toolbar button still works exactly as described above, but in modern releases the editor also automatically detects MS Word, Outlook, OneNote, Excel, and PowerPoint clipboard payloads on a regular Ctrl+V paste and runs the same cleanup pipeline for you. End users get clean HTML even when they paste with the keyboard or right-click → Paste, without ever knowing the [W] button exists.

This behavior is controlled by Options.AutoDetectWordPaste on the WpfHtmlEditor control:

// Default = true. Office 2007 through 2025+ payloads are auto-cleaned on Ctrl+V.
wpfHtmlEditor1.Options.AutoDetectWordPaste = true;

Visual Studio property grid showing Options.AutoDetectWordPaste = true on the WPF HTML Editor sub-properties of Options

How the detection works

The clipboard service inspects the CF_HTML fragment for the well-known Microsoft Office signatures (xmlns:o="urn:schemas-microsoft-com:office:office", the mso- CSS prefix, the <!--StartFragment--> wrapper, etc.). When any of those is present, the paste is routed through the same modern Word-cleanup pipeline that the [W] button uses; otherwise the standard browser paste is used.

When to opt out

Opt out only if you have a deliberate reason to keep the raw Office HTML — for example, you have your own downstream sanitizer or you want to preserve mso- styles for an Outlook signature workflow:

// Restore the legacy behavior: regular Ctrl+V leaves the Office payload intact;
// users must click the [W] toolbar button to clean it.
wpfHtmlEditor1.Options.AutoDetectWordPaste = false;

VB.NET

wpfHtmlEditor1.Options.AutoDetectWordPaste = True   ' default
wpfHtmlEditor1.Options.AutoDetectWordPaste = False  ' legacy [W]-only behavior

Before and after comparison showing raw Microsoft Word clipboard HTML on the left and the cleaned auto-detected paste output on the right inside the WPF HTML Editor

Last updated on May 12, 2026