# rich-text-editor-paste-from-ms-word

> Rich text editor sample cleaning paste content from Microsoft Word automatically.

**Framework:** javascript  **Component:** RichTextEditor  **Variant:** paste-from-ms-word

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/javascript/rich-text-editor-paste-from-ms-word.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-richtexteditor
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/rich-text-editor-paste-from-ms-word/rich-text-editor.html

```html
<div class="col-lg-8 control-section">
    <div class="control-wrapper">
        <div class="sample-container">
            <div class="default-section">
                <div id="container">
                    <h4>Paste Cleanup in Rich Text Editor<br></h4><p>The Rich Text Editor automatically <strong>cleans up formatted content</strong> when you paste from external sources like Word, Google Docs, or web pages.</p><p><b>Paste Cleanup properties:</b></p><ul>
                    <li><strong>Prompt </strong>- specifies whether to enable the prompt when pasting in Rich Text Editor
                    </li>
                    <li><strong>Plain Text </strong>- specifies whether to paste as plain text or not in Rich Text Editor.
                    </li>
                    <li><strong>Keep Format</strong>- specifies whether to keep or remove the format when pasting in Rich Text Editor.
                    </li>
                    <li><strong>Denied Tags</strong> - specifies the tags to restrict when pasting in Rich Text Editor.
                    </li>
                    <li><strong>Denied Attributes</strong> - specifies the attributes to restrict when pasting in Rich Text Editor.
                    </li>
                    <li><strong>Allowed Style Properties</strong> - specifies the allowed style properties when pasting in Rich Text Editor.
                    </li>
                </ul><p><span><strong>Try It Out!</strong></span></p><p>Copy content from a web page or document and paste it here. The editor will display a prompt and allow you to input your options.</p>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="col-lg-4 property-section">
    <div title="Properties">
        <table id="property" title="Properties">
            <tbody>
                <tr>
                    <td>
                        <div>Format Option</div>
                    </td>
                    <td>
                        <div>
                            <select id="formattingOption"> 
                                <option value="prompt">Prompt</option>
                                <option value="plainText">Plain Text</option>
                                <option value="keepFormat">Keep Format</option>
                                <option value="cleanFormat">Clean Format</option>
                            </select>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div>Denied Tags </div>
                    </td>
                    <td>
                        <div>
                            <input id="deniedTags" type="text" class="e-input" placeholder="'img[!href]', 'h1'">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div>Denied Attributes </div>
                    </td>
                    <td>
                        <div>
                            <input id="deniedAttributes" type="text" class="e-input" placeholder="'id', 'title'">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div>Allowed Style Properties </div>
                    </td>
                    <td>
                        <div>
                            <input id="allowedStyleProperties" type="text" class="e-input" placeholder="'href', 'style'">
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
```

### src/components/rich-text-editor-paste-from-ms-word/rich-text-editor.ts

```typescript
import { RichTextEditor, Toolbar, Link, Image, HtmlEditor, QuickToolbar, PasteCleanup, Table, Video, Audio, ClipBoardCleanup, AutoFormat } from '@syncfusion/ej2-richtexteditor';
import { DropDownList } from '@syncfusion/ej2-dropdowns';
import { isNullOrUndefined } from '@syncfusion/ej2-base';
RichTextEditor.Inject(Toolbar, Link, Image, HtmlEditor, QuickToolbar, Table, PasteCleanup, Video, Audio, ClipBoardCleanup, AutoFormat);

export function initRichTextEditorPasteFromMsWord(): void {
    let defaultRTE: RichTextEditor = new RichTextEditor({
        pasteCleanupSettings: {
            prompt: true,
            plainText: false,
            keepFormat: false
        }
    });
    defaultRTE.appendTo('#container');

    let formatOption: DropDownList = new DropDownList({
        index: 0,
        popupHeight: '200px',
        change: () => { valueChange(); }
    });
    formatOption.appendTo('#formattingOption');

    function valueChange(): void {
        if (formatOption.value === 'prompt') {
            defaultRTE.pasteCleanupSettings.prompt = true;
        } else if (formatOption.value === 'plainText') {
            defaultRTE.pasteCleanupSettings.prompt = false;
            defaultRTE.pasteCleanupSettings.plainText = true;
        } else if (formatOption.value === 'keepFormat') {
            defaultRTE.pasteCleanupSettings.prompt = false;
            defaultRTE.pasteCleanupSettings.plainText = false;
            defaultRTE.pasteCleanupSettings.keepFormat = true;
        } else if (formatOption.value === 'cleanFormat') {
            defaultRTE.pasteCleanupSettings.prompt = false;
            defaultRTE.pasteCleanupSettings.plainText = false;
            defaultRTE.pasteCleanupSettings.keepFormat = false;
        }
    }
    let allowedStylePropsElem: HTMLElement = document.getElementById('allowedStyleProperties');
    let deniedTagsElem: HTMLElement = document.getElementById('deniedTags');
    let deniedAttrsElem: HTMLElement = document.getElementById('deniedAttributes');
    allowedStylePropsElem.addEventListener('blur', (e: FocusEvent) => {
        onPasteCleanupSettingsChange((e.target as HTMLInputElement).value, 'allowedStyleProps');
        defaultRTE.dataBind();
    });
    deniedAttrsElem.addEventListener('blur', (e: FocusEvent) => {
        onPasteCleanupSettingsChange((e.target as HTMLInputElement).value, 'deniedAttrs');
        defaultRTE.dataBind();
    });
    deniedTagsElem.addEventListener('blur', (e: FocusEvent) => {
        onPasteCleanupSettingsChange((e.target as HTMLInputElement).value, 'deniedTags');
        defaultRTE.dataBind();
    });

    function onPasteCleanupSettingsChange(value: string, settingsProperty: string): void {
        if (!isNullOrUndefined(value)) {
            const arrayValue = value.split(',').map((item) => item.trim().replace(/^['"]|['"]$/g, ''));
            defaultRTE.pasteCleanupSettings[settingsProperty] = arrayValue.filter((prop) => prop !== '');
        }
    }
}

```
