Framework-neutral TypeScript codecs for MS-CFB / OLE2 compound files and the legacy binary Office formats built on them. Parse a file into a typed, editable document, change supported content, and serialize it again while preserving the bytes you did not touch.
| Format | Extension | Document class |
|---|---|---|
| Word 97-2003 | .doc |
DocDocument |
| Excel BIFF8 | .xls |
XlsDocument |
| PowerPoint 97-2003 | .ppt |
PptDocument |
| Visio (binary) | .vsd |
VsdDocument |
| Any compound file | any | CfbDocument |
Documentation · Limitations · npm
npm install @christophervr/ole2No runtime dependencies. ESM with TypeScript declarations, for Node.js 22+ and browsers.
import { parseOle2, parseDoc, parseXls, parsePpt, parseVsd } from '@christophervr/ole2';
const document = parseOle2(bytes); // CFB | DOC | XLS | PPT | VSD
if (document.kind === 'xls') document.sheets[0]!.cell(1, 0).value = 'Updated';
const ppt = parseOle2<'ppt'>(pptBytes, { expect: 'ppt' });
ppt.slides[0]!.texts[0]!.text = 'Native title updated';
const saved = ppt.serialize();parseDoc, parseXls, parsePpt and parseVsd return the concrete classes. Supported setters commit transactionally; an unsupported edit throws without changing bytes or dirty state. Default parsing falls back to a CFB inspection view with diagnostics when an Office model is unsupported or ambiguous, while a checked expect throws instead.
import { buildOle2, parseOle2 } from '@christophervr/ole2';
const bytes = buildOle2(new Map([['Example', new Uint8Array([1, 2, 3])]]));
console.log(parseOle2(bytes, { expect: 'cfb' }).getStream('Example'));- Document models for DOC, XLS, PPT and VSD with checked parsing and transactional edits.
- MS-CFB containers: stream reading and writing, mini streams, FAT/DIFAT, in-place stream resizing and SummaryInformation metadata.
- Word: main-body paragraphs, rich runs, direct formatting and guarded text edits.
- Excel: whole-workbook reading (cells, cached formula results, styles, merges, comments, hyperlinks, names) and typed cell edits.
- PowerPoint: active slides, text, shapes and notes, bounded text and geometry edits, and a binary
.pptwriter (buildPptFile). - Visio: version 11 pages, shapes, drawing order, transforms, text and geometry, with preserving text and transform edits.
- Publisher: container inspection.
Each format has a supported subset, which is documented on the site rather than here: see the format guides and the limitations page.
The documentation site is built with VitePress from the docs/ directory.
Run it locally with bun run docs:dev.
bun install --frozen-lockfile
bun run typecheck
bun run test
bun run build
bun run test:package
bun run docs:buildThe packed-package smoke test installs the tarball into an independent temporary npm project and exercises the public API. The build clears its own dist directory so removed codecs cannot remain in a release. Only compiled output, license, notice and this readme ship to npm.
Apache-2.0.