Overview

Edit DOCX text, formatting, tables, and review data with an Office.js-compatible API on a server or in an open browser editor.

@docx-editor.dev/editor-api edits DOCX files through a supported subset of the Office.js object model. It runs on a server over DOCX bytes or in the browser against an open editor.

Install and edit a document

Install the API and its engine peer dependency:

npm install @docx-editor.dev/editor-api @docx-editor.dev/core

The following server example replaces every match and saves the result:

import { readFile, writeFile } from 'node:fs/promises';
import { DocxEditor } from '@docx-editor.dev/editor-api';

const runtime = await DocxEditor.createServer(await readFile('contract.docx'), {
  author: 'Review bot',
});
try {
  await runtime.run(async (context) => {
    const matches = context.document.body.search('$50k');
    matches.load('items');
    await context.sync(); // Read the matching ranges.

    for (const match of matches.items) match.insertText('$500k', 'Replace');
    await context.sync(); // One atomic batch: all of the writes, or none.
  });
  await writeFile('contract.filled.docx', await runtime.save());
} finally {
  runtime.dispose();
}

To make these edits tracked changes, set context.document.changeTrackingMode = 'TrackMineOnly' first. For supported tracked operations, see Tracked changes.

Choose a host

HostFactorySave throughRequirements
ServerDocxEditor.createServer()runtime.save()DOCX bytes and Node.js ^20.16.0 || >=22.3.0
BrowserDocxEditor.createBrowser() from /browserThe owning editorAn attached core, React, or Vue editor
CollaborativeDocxEditor.createCollaborative()runtime.save()DOCX bytes and an EditorCollaborationSession

For complete host examples, options, and capabilities, see Runtime and setup.

Find a task guide

TaskGuide
Load properties, sync batches, and recover from errorsBatching, loading, and errors
Read, insert, replace, or remove textText and ranges
Split a paragraphSplit a paragraph
Insert an equation from OOXMLInsert an equation
Find matches or use bookmarksSearch and navigation
Set fonts, paragraph properties, styles, or linksFormatting and styles
Create and configure listsLists and numbering
Edit table values, rows, columns, and cellsTables and cells
Insert and resize imagesInline pictures
Insert fields or calculate PAGE and NUMPAGESFields and pagination
Set page geometry and edit headers, footers, notes, or text boxesPage layout and stories
Fill template controlsContent controls
Discuss content and manage threadsComments
Create, inspect, accept, or reject tracked changesTracked changes
Propose structural edits as tracked changesPropose several structural edits in one run
Find any public memberAPI member directory

Requirements and limits

  • The package uses the EigenPal Pro License. For options, see pricing.
  • The API and editor adapters must share one resolved copy of the @docx-editor.dev/core peer dependency.
  • Comments, replies, and tracked edits require an author. Browser review writes also require the Pro review module and an editable document.
  • Only an explicit await context.sync() applies queued operations. Returning from run() does not.
  • A failed load after a commit can leave writes applied. If debugInfo.innerError.code is edit.read-after-commit, do not repeat the edit. For recovery, see Batching, loading, and errors.
  • The API covers a supported subset of Office.js. For differences, see Office.js compatibility.

Next steps