DOC · WORD 97–2003
Legacy Word
API guide
The Word helpers read plain text from the main document body of binary .doc files. The edit API replaces one existing paragraph while carrying over its paragraph and first-run formatting.
IMPLEMENTATION NOTES
What works
Use readOleDocParagraphs to get main-body paragraph strings. writeOleDocParagraphEdit appends replacement text and updates the piece table rather than shifting bytes it does not understand.
- Paragraph formatting and the first run’s character formatting are carried to the replacement.
- The writer supports files whose only populated character-position table is the required section table.
- A failed or unsupported edit returns the original byte array unchanged.
IMPLEMENTATION NOTES
Known limits
This is not a general Word parser or renderer. It does not expose tables, headers, footers, footnotes, comments, fields, bookmarks, or rich run structure through this API.
- Edits are refused when character-position tables for footnotes, annotations, fields, or bookmarks are populated.
- Paragraph breaks in replacement text are converted to spaces.
- The API operates on existing main-body paragraph indexes; it does not add or remove paragraphs.
QUICK EXAMPLE
Use the supported API
Import the package root unless a subpath is shown in the sample.
import { readOleDocParagraphs, writeOleDocParagraphEdit } from '@christophervr/ole2';
const paragraphs = readOleDocParagraphs(docBytes);
if (paragraphs) {
console.log(paragraphs[0]);
const edited = writeOleDocParagraphEdit(docBytes, 0, 'Updated paragraph');
if (edited === docBytes) console.log('Edit was unsupported or unsafe.');
}This guide documents the current package API. Unsupported or unsafe operations are described explicitly; format detection alone does not imply content support.
Back to format overview