@christophervr/ole2

中文文档
0.14.0发布于 2026/10/30Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 9605

Shared MS-CFB compound-file and legacy Microsoft Office binary codecs

原始使用文档
文档目录6 节
  1. Install
  2. Quick start
  3. What is included
  4. Documentation
  5. Development
  6. License

@christophervr/ole2

npm version CI license types

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.

FormatExtensionDocument class
Word 97-2003.docDocDocument
Excel BIFF8.xlsXlsDocument
PowerPoint 97-2003.pptPptDocument
Visio (binary).vsdVsdDocument
Any compound fileanyCfbDocument

Documentation · Limitations · npm


Install

npm install @christophervr/ole2

No runtime dependencies. ESM with TypeScript declarations, for Node.js 22+ and browsers.

Quick start

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'));

What is included

  • 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.
  • Word formatting: readDocFormatting(bytes, limits?) returns the stylesheet, list definitions and instances, fonts, and main-story paragraphs and runs keyed by character position, with typed character and paragraph properties resolved through the style cascade (raw style references kept). Read-only; it is bounded by DocFormattingLimits and returns undefined for unreadable or encrypted files.
  • Word model: readDocModel(bytes, limits?) composes formatting, objects and structure into one block tree per story: paragraphs with formatted inline items (text, pictures, field marks, bookmarks, note and comment references, shape and text box anchors), tables with nested cell blocks, sections with their header and footer stories, styles, lists and fonts. Every story is formatted, not only the main one. See docs/doc-model.md.
  • 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 .ppt writer (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.

Documentation

The documentation site is built with VitePress from the docs/ directory.

Run it locally with bun run docs:dev.

Development

bun install --frozen-lockfile
bun run typecheck
bun run test
bun run build
bun run test:package
bun run docs:build

The 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.

License

Apache-2.0.

版本与发布记录

@christophervr/ole2 共发布 16 个版本,首次发布于 2026/09/27;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.14.0latest2026/10/3010 天前
0.13.02026/10/061 个月前
0.12.02026/10/031 个月前
0.11.02026/10/031 个月前
0.10.12026/10/031 个月前
0.10.02026/10/031 个月前

关于 @christophervr/ole2 的常见问题

@christophervr/ole2 是什么?

Shared MS-CFB compound-file and legacy Microsoft Office binary codecs

如何安装 @christophervr/ole2?

在项目目录运行 npm install @christophervr/ole2,或使用 pnpm add / yarn add / bun add。

@christophervr/ole2 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@christophervr/ole2 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@christophervr/ole2 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@christophervr/ole2 可以商用吗?

@christophervr/ole2 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@christophervr/ole2 的下载量有多少?

根据 npm 官方下载统计,@christophervr/ole2 在 2026/10/10 – 2026/11/08 这 30 天内被下载 9,605 次,日均约 320 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@christophervr/ole2 还在维护吗?

最新版本 0.14.0 发布于 2026/10/30(10 天前);至今共发布 16 个版本,其中过去 12 个月发布了 16 个;首次发布于 2026/09/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。