npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@coco-vexel/coco-office

v1.0.7

Published

CocoOffice — XML / OOXML 文档操作底座(Word / Excel / PPT)

Readme

@coco-vexel/coco-office

Read, query, modify and export Word (.docx), Excel (.xlsx) and PowerPoint (.pptx) documents in JavaScript. Core supplies document/package APIs; it does not render a full Office application or call Office host APIs.

Installation and requirements

npm install @coco-vexel/coco-office

These instructions target the initial npm release; availability is subject to publication. Use Node.js 22 or 24 for the examples below, saved as .mjs files. ESM, CommonJS and TypeScript declarations are included. Browser applications should use a bundler and supply file selection/download handling. Neither Microsoft Office nor a backend is required for local document operations.

Quick start: create a Word document

Save as word.mjs, then run node word.mjs. No input document is required. It creates hello.docx in the current directory; wx prevents overwriting an existing file.

import { writeFile } from 'node:fs/promises';
import { WordDocument } from '@coco-vexel/coco-office/word';

const doc = await WordDocument.createBlank({ docId: 'hello', mode: 'inline' });
try {
  const { paragraphs } = await doc.paragraphs.list({ pagination: { mode: 'all' } });
  await paragraphs[0].replaceWith('Hello from Coco Office');
  await writeFile('hello.docx', await doc.toZip(), { flag: 'wx' });
} finally {
  await doc.dispose();
}

For an existing DOCX, use WordDocument.fromZip(await readFile(inputPath), { docId: 'edit', mode: 'inline' }). Write the returned bytes to a separate output path. paragraphs.list() supports pagination; request pagination: { mode: 'all' } when the operation needs all paragraphs.

Edit an Excel workbook

Save as excel.mjs; run node excel.mjs input.xlsx Sheet1. The named sheet must already exist. This writes edited.xlsx and leaves the input file unchanged. The example writes a literal value, not a formula.

import { readFile, writeFile } from 'node:fs/promises';
import { ExcelWorkbook } from '@coco-vexel/coco-office/excel';

const [, , inputPath, sheetName = 'Sheet1'] = process.argv;
if (!inputPath) throw new Error('Usage: node excel.mjs input.xlsx [sheetName]');
const book = await ExcelWorkbook.fromZip(await readFile(inputPath), {
  workbookId: 'example',
  mode: 'inline',
});
try {
  await book.worksheets
    .getItem(sheetName)
    .getRange('B2')
    .setValues([[42]]);
  await writeFile('edited.xlsx', await book.toZip(), { flag: 'wx' });
} finally {
  await book.dispose();
}

Edit a PowerPoint text shape

Save as ppt.mjs; run node ppt.mjs input.pptx Title. The first slide must contain a text shape with the supplied name. This produces edited.pptx; it does not render slide images.

import { readFile, writeFile } from 'node:fs/promises';
import { Presentation } from '@coco-vexel/coco-office/ppt';

const [, , inputPath, shapeName = 'Title'] = process.argv;
if (!inputPath) throw new Error('Usage: node ppt.mjs input.pptx [shapeName]');
const deck = await Presentation.fromZip(await readFile(inputPath));
try {
  await deck.slides.getItem(0).shapes.getItem(shapeName).text.setText('Updated title');
  await writeFile('edited.pptx', await deck.toZip(), { flag: 'wx' });
} finally {
  await deck.dispose();
}

Public entrypoints

| Import | Purpose | | ----------------------------------------------------------------- | ------------------------------------------------------------ | | @coco-vexel/coco-office/pack | OOXML ZIP/Flat OPC package I/O | | @coco-vexel/coco-office/word | Word document, paragraphs/ranges and supported edits | | @coco-vexel/coco-office/word-view | Word projection/index helpers for views | | @coco-vexel/coco-office/excel | Worksheets, cells/ranges, formula subset and workbook export | | @coco-vexel/coco-office/ppt | Slides, text/shapes/tables and presentation export | | @coco-vexel/coco-office/shared | Shared utilities | | @coco-vexel/coco-office/kernel-worker, /kernel-worker-browser | Word Node/browser worker bootstraps | | @coco-vexel/coco-office/excel-worker, /excel-worker-browser | Excel Node/browser worker bootstraps |

ESM example: import { WordDocument } from '@coco-vexel/coco-office/word'. CommonJS example: const { WordDocument } = require('@coco-vexel/coco-office/word'). Use domain entrypoints for the APIs you need; do not import src/ or undocumented dist/ paths.

Lifecycle, browser use and limitations

Call dispose() in finally, including when an edit/export fails. The examples use inline mode, which requires no Worker setup. Node Worker mode requires WordDocument.setWorkerBundleUrl(...) or ExcelWorkbook.setWorkerBundleUrl(...); browser Workers require the corresponding browser factory. Do not load Node Worker bootstraps as browser entrypoints. Inline mode can block the UI for large documents; profile representative files before choosing a worker configuration.

In a browser, read new Uint8Array(await file.arrayBuffer()) and pass it to fromZip. Download output with a Blob/object URL; loading and saving files are application responsibilities. To display/edit documents visually, use @coco-vexel/coco-office-editor.

Word layout, Excel formulas/rich objects, and PPT advanced objects/animations have feature-specific limits. Unknown-part preservation and export/reparse tests do not guarantee all edits are supported or pixel-identical rendering in Office. A missing sheet/shape, malformed input or unsupported operation should be handled by the caller; never discard the original file after an unchecked export.

Documentation

| Area | Start here | Detailed reference | | ---------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | General | Getting started | API index and cookbook | | Word | Word documentation | Paragraphs, ranges, tables, comments, and revisions | | Excel | Excel documentation | API reference and formula support | | PowerPoint | PowerPoint documentation | API reference and style capabilities | | Runtime | Runtime, tests and demos | Runtime modes and host integration |

GitHub Releases also provide a self-contained SDK bundle with this package, offline documentation and runnable Word/Excel/PowerPoint examples.

Runnable repository demo

For synthetic three-format fixtures and round-trip assertions, clone the repository, run corepack pnpm install --frozen-lockfile, corepack pnpm build, then corepack pnpm example. These are repository commands, not scripts shipped with the installed npm package.

Report reproducible SDK issues with package version and a minimal synthetic document at GitHub Issues. Follow SECURITY.md for private vulnerability reports.

Apache-2.0 for original code; see LICENSE and THIRD_PARTY_NOTICES.md in the package.