paste-from-office.md 3.1 KB


menu-title: Paste from Word

category: features

{@snippet features/build-paste-from-office-source}

Pasting content from Microsoft Word

The Paste from Word feature is provided through the {@link module:paste-from-office/pastefromoffice~PasteFromOffice} plugin.

This feature allows you to paste content from Microsoft Word and maintain original structure and formatting. After creating a document in Microsoft Word you can simply copy it to CKEditor and retain basic text styling, heading levels, links, lists, tables and images.

When the plugin is enabled, it automatically detects Word content and transforms its structure and formatting to clean HTML which is then transformed into semantic content by the editor.

Pasted content may be additionally modified or filtered by altering clipboard content on {@link module:clipboard/clipboard~Clipboard#event:inputTransformation `view.Document#inputTransformation`} event.

Demo

To test how Paste from Office works, download the sample Word document, open it in Microsoft Word, copy the content and paste it into CKEditor below.

{@snippet features/paste-from-office}

Installation

This feature is enabled by default in all builds. The installation instructions are for developers interested in building their own, custom rich text editor.

To add this feature to your editor, install the @ckeditor/ckeditor5-paste-from-office package:

npm install --save @ckeditor/ckeditor5-paste-from-office

Then add PasteFromOffice plugin to your plugin list:

import PasteFromOffice from '@ckeditor/ckeditor5-paste-from-office/src/pastefromoffice';

ClassicEditor
	.create( document.querySelector( '#editor' ), {
		plugins: [ PasteFromOffice, Bold, ... ]
	} )
	.then( ... )
	.catch( ... );

Support for different text editors

While the main focus of the Paste from Office plugin is on correctly transforming content pasted from Microsoft Word it also provides basic support for other text editors (see this comment covering support for other text editors).

Pasting content from Microsoft Excel will keep the correct table structure. Pasting content from Google Docs maintains basic styles, headings, links, tables and images. Other known text editors like Libre Office or Pages also have its basic formatting preserved.

If you think that any of the above needs improvements, you may add +1 in the related issues (see issues for improving paste support from Excel, Google Docs, Libre Office or Pages). If there is any text editor you would like to see a support for, you may open new feature request.