Paste from Word and Outlook

    Text copied from Word or Outlook often includes Office-specific HTML as well as the visible formatting. Automatic Word-paste detection cleans that markup before insertion. Enable the cleanup as shown below, then use Pasting if your application needs additional rules.

    Pasted content from Microsoft Word carries a lot of Word-specific markup: MsoNormal classes, <o:p> namespace tags, conditional comments aimed at older Internet Explorer, and a long list of mso-* style properties. Left in place, this noise can break downstream consumers such as PDF exporters (collapsed headings, wrong bullet spacing, fonts changing mid-paragraph).

    WpfHtmlEditor auto-detects Word content on the clipboard and strips this noise before inserting it. Set MsIePasteBehavior to false so the editor runs its paste pipeline. Keep AutoDetectWordPaste enabled to recognize and clean Word markup:

    // Use the editor paste pipeline, then enable Word detection.
    editor.Options.MsIePasteBehavior = false;
    editor.Options.AutoDetectWordPaste = true;
    ' Use the editor paste pipeline, then enable Word detection.
    editor.Options.MsIePasteBehavior = False
    editor.Options.AutoDetectWordPaste = True
    The WPF HTML editor's source view of the same paragraph pasted from Microsoft Word twice: with auto-detection off the markup carries MsoNormal classes, mso-style properties and o:p tags, and with auto-detection on the same text is ordinary HTML
    The WPF HTML editor's source view of the same paragraph pasted from Microsoft Word twice: with auto-detection off the markup carries MsoNormal classes, mso-style properties and o:p tags, and with auto-detection on the same text is ordinary HTML

    You may need cleanup beyond the automatic Word-noise removal, such as enforcing a house style (a single font and text color) or capping the size of a paste. Subscribe to the Pasting event: it fires after the built-in Word cleanup has run and gives you the already-cleaned HTML, so you can strip anything else you do not want, or cancel the paste outright.

    Use e.IsPastingFromMsWord to apply extra rules only to Word-sourced pastes; pastes from plain text editors, IDEs, or web pages pass through untouched. The example below strips inline color and font-family styles and cancels pastes larger than 200 KB:

    public MainWindow()
    {
        InitializeComponent();
        editor.Pasting += Editor_Pasting;
    }
    
    private void Editor_Pasting(object sender, PastingHtmlEventArgs e)
    {
        if (e.IsPastingFromMsWord && !string.IsNullOrEmpty(e.PastingHtml))
        {
            // House style: drop inline colors and font-family choices.
            e.PastingHtml = Regex.Replace(e.PastingHtml, @"(?<![-\w])(?:color)\s*:\s*(?:[^;'""<>{}]|""[^""';<>{}]*""|'[^'"";<>{}]*')*;?", "");
            e.PastingHtml = Regex.Replace(e.PastingHtml, @"(?<![-\w])(?:font-family)\s*:\s*(?:[^;'""<>{}]|""[^""';<>{}]*""|'[^'"";<>{}]*')*;?", "");
        }
    
        if (e.PastingHtml != null && e.PastingHtml.Length > 200_000)
            e.Cancel = true;
    }
    Public Sub New()
        InitializeComponent()
        AddHandler editor.Pasting, AddressOf Editor_Pasting
    End Sub
    
    Private Sub Editor_Pasting(sender As Object, e As PastingHtmlEventArgs)
        If e.IsPastingFromMsWord AndAlso Not String.IsNullOrEmpty(e.PastingHtml) Then
            ' House style: drop inline colors and font-family choices.
            e.PastingHtml = Regex.Replace(e.PastingHtml, "(?<![-\w])(?:color)\s*:\s*(?:[^;'""<>{}]|""[^""';<>{}]*""|'[^'"";<>{}]*')*;?", "")
            e.PastingHtml = Regex.Replace(e.PastingHtml, "(?<![-\w])(?:font-family)\s*:\s*(?:[^;'""<>{}]|""[^""';<>{}]*""|'[^'"";<>{}]*')*;?", "")
        End If
    
        If e.PastingHtml IsNot Nothing AndAlso e.PastingHtml.Length > 200_000 Then e.Cancel = True
    End Sub
    Microsoft Word document beside the WPF HTML Editor after a paste: a Pasting event handler has removed the direct colour and font Word applied, while the heading, wording and structure of the pasted content are unchanged.
    Microsoft Word document beside the WPF HTML Editor after a paste: a Pasting event handler has removed the direct colour and font Word applied, while the heading, wording and structure of the pasted content are unchanged.

    The IsPastingFromMsWord flag on the event args identifies which pastes came from Word, so you can apply cleanup rules selectively. Pastes from regular text editors, IDEs, or web pages pass through untouched.

    The toolbar also includes a dedicated "Paste from Word" button. Clicking it runs the Word cleanup unconditionally, even if the clipboard content is not auto-detected as Word-flavored. Use this button whenever you are not sure of the paste source.

    Ask your AI to do this

    Connect the SpiceLogic MCP server, then give your coding assistant this prompt.

    I use the SpiceLogic WPF HTML Editor. Help me set MsIePasteBehavior to false, enable AutoDetectWordPaste and handle Pasting for additional cleanup. Keep unrelated pastes unchanged. Confirm the exact API names, types and defaults with the SpiceLogic MCP documentation, then show the changes for my project.

    Last updated on Oct 9, 2026

    Put this into practice.

    Clone the C# and VB.NET sample projects from GitHub. Start with Quickstart, then explore the feature samples.

    Prefer a guided look? Book a free live demo with our engineers - live on Zoom or Teams, never a chatbot.