DOCX Import
Use @blocknote/docx-importer to open a Word .docx file in BlockNote. It uses DocSpec compiled to WebAssembly, so the file is converted in the browser without uploading it.
npm install @blocknote/docx-importerPass the File from a file picker to importDocx, then use the returned blocks to replace the editor's content:
import type { BlockNoteEditor } from "@blocknote/core";
import { importDocx } from "@blocknote/docx-importer";
async function openWordDocument(editor: BlockNoteEditor, file: File) {
const result = await importDocx(file);
if (result.error === "invalid-docx") {
return "This file could not be imported. Choose a valid .docx file.";
}
editor.replaceBlocks(
editor.document,
result.blocks.length ? result.blocks : [{ type: "paragraph" }],
);
}importDocx also accepts a Blob or Uint8Array. It returns blocks for the default BlockNote schema. Import is lossy: it brings in supported content and formatting, but does not preserve Word's page layout. Keep the original file if you need that layout.
Try the Import DOCX example with your own Word document. To write a Word file from BlockNote, see DOCX export.