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/coreThe 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
| Host | Factory | Save through | Requirements |
|---|---|---|---|
| Server | DocxEditor.createServer() | runtime.save() | DOCX bytes and Node.js ^20.16.0 || >=22.3.0 |
| Browser | DocxEditor.createBrowser() from /browser | The owning editor | An attached core, React, or Vue editor |
| Collaborative | DocxEditor.createCollaborative() | runtime.save() | DOCX bytes and an EditorCollaborationSession |
For complete host examples, options, and capabilities, see Runtime and setup.
Find a task guide
| Task | Guide |
|---|---|
| Load properties, sync batches, and recover from errors | Batching, loading, and errors |
| Read, insert, replace, or remove text | Text and ranges |
| Split a paragraph | Split a paragraph |
| Insert an equation from OOXML | Insert an equation |
| Find matches or use bookmarks | Search and navigation |
| Set fonts, paragraph properties, styles, or links | Formatting and styles |
| Create and configure lists | Lists and numbering |
| Edit table values, rows, columns, and cells | Tables and cells |
| Insert and resize images | Inline pictures |
| Insert fields or calculate PAGE and NUMPAGES | Fields and pagination |
| Set page geometry and edit headers, footers, notes, or text boxes | Page layout and stories |
| Fill template controls | Content controls |
| Discuss content and manage threads | Comments |
| Create, inspect, accept, or reject tracked changes | Tracked changes |
| Propose structural edits as tracked changes | Propose several structural edits in one run |
| Find any public member | API 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/corepeer 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 fromrun()does not. - A failed load after a commit can leave writes applied. If
debugInfo.innerError.codeisedit.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.