Skip to content

DemoMacro/office-open

Repository files navigation

office-open

GitHub Contributor Covenant

The all-in-one TypeScript toolkit for Office documents. Generate, parse, and patch .docx, .pptx, .xlsx files — fully typed, spec-compliant, and works everywhere. Compatible with Microsoft Office, WPS Office, LibreOffice, and Google Workspace.

Features

  • 📄 All-in-One — Word (.docx), Excel (.xlsx), and PowerPoint (.pptx) in one cohesive API, no Office dependency
  • 📐 Spec-Compliant — Output validates against OOXML Transitional XSD schemas (ISO/IEC 29500), compatible with Microsoft Office, WPS Office, LibreOffice, and Google Workspace
  • 🔒 Fully Typed — Complete TypeScript definitions with full autocomplete and type safety
  • 🎯 Pure JSON API — Define documents as plain JSON objects, zero class instantiation, ideal for AI agents
  • 🔄 Parse & Patch — Read existing .docx, .pptx, .xlsx files for round-trip workflows, or patch templates by placeholder replacement
  • 🎨 Rich Content — Paragraphs, tables, images, charts, SmartArt, math equations, effects, animations, and more
  • High Performance — Optimized for large documents and batch processing with native zlib compression
  • 🌐 Cross-Platform — Node.js, browsers, Deno, Bun. Export to Buffer, Blob, Base64, stream, or string

Packages

Package Version Description
@office-open/docx npm Word document generation, parsing, and patching
@office-open/pptx npm PowerPoint generation, parsing, and patching
@office-open/xlsx npm Spreadsheet generation, parsing, and patching
@office-open/core npm Shared OOXML infrastructure, charts, unit converters
@office-open/xml npm Low-level XML parsing and serialization
office-open npm Umbrella: all packages + CLI + AI SDK tools

Quick Start

DOCX Generation

# pnpm
pnpm add @office-open/docx

# npm
npm install @office-open/docx

# yarn
yarn add @office-open/docx

# bun
bun add @office-open/docx
import { generateDocumentSync } from "@office-open/docx";
import { writeFileSync } from "node:fs";

const buffer = generateDocumentSync({
  sections: [
    {
      children: [{ paragraph: { children: [{ text: "Hello World", bold: true }] } }],
    },
  ],
});
writeFileSync("document.docx", buffer);

PPTX Generation

# pnpm
pnpm add @office-open/pptx

# npm
npm install @office-open/pptx

# yarn
yarn add @office-open/pptx

# bun
bun add @office-open/pptx
import { generatePresentationSync } from "@office-open/pptx";
import { writeFileSync } from "node:fs";

const buffer = generatePresentationSync({
  slides: [
    {
      children: [
        {
          shape: {
            x: 100,
            y: 100,
            width: 600,
            height: 400,
            textBody: { children: [{ paragraph: { children: ["Hello World"] } }] },
            fill: "4472C4",
          },
        },
      ],
    },
  ],
});
writeFileSync("presentation.pptx", buffer);

XLSX Generation

# pnpm
pnpm add @office-open/xlsx

# npm
npm install @office-open/xlsx

# yarn
yarn add @office-open/xlsx

# bun
bun add @office-open/xlsx
import { generateWorkbookSync } from "@office-open/xlsx";
import { writeFileSync } from "node:fs";

const buffer = generateWorkbookSync({
  worksheets: [
    {
      name: "Sheet1",
      rows: [
        { cells: [{ value: "Name" }, { value: "Score" }] },
        { cells: [{ value: "Alice" }, { value: 95 }] },
        { cells: [{ value: "Bob" }, { value: 87 }] },
      ],
    },
  ],
});
writeFileSync("workbook.xlsx", buffer);

Umbrella Package

Install all packages at once with CLI, AI SDK tools, and schemas:

# pnpm
pnpm add office-open

# npm
npm install office-open

# yarn
yarn add office-open

# bun
bun add office-open
import { generate } from "office-open/generate";
import { writeFileSync } from "node:fs";

const buffer = await generate({
  type: "docx",
  options: {
    sections: [{ children: [{ paragraph: "Hello from office-open!" }] }],
  },
  outputType: "nodebuffer",
});
writeFileSync("output.docx", buffer);
# CLI usage
npx office-open xlsx input.json "output.xlsx"

Parse Existing Files

Read and inspect existing .docx, .pptx, and .xlsx files into structured objects:

// DOCX
import { parseDocument } from "@office-open/docx";
const opts = parseDocument(buffer);
// opts.sections — document sections
// opts.title, opts.creator — core properties

// PPTX
import { parsePresentation } from "@office-open/pptx";
const opts = parsePresentation(buffer);
// opts.slides — slide array
// opts.size, opts.title — presentation properties

// XLSX
import { parseWorkbook } from "@office-open/xlsx";
const opts = parseWorkbook(buffer);
// opts.worksheets — worksheet array
// opts.worksheets[0].rows — row/cell data

JSON API

Define documents as plain JSON objects — perfect for AI agents. Zero class instantiation, pure data in and binary out:

import { generateDocumentSync } from "@office-open/docx";

const buffer = generateDocumentSync({
  sections: [
    {
      children: [
        { paragraph: { heading: "Heading1", children: ["Document Title"] } },
        { paragraph: { children: [{ text: "Body text", italic: true }] } },
        {
          table: {
            rows: [
              { cells: [{ children: [{ paragraph: "A1" }] }, { children: [{ paragraph: "B1" }] }] },
              { cells: [{ children: [{ paragraph: "A2" }] }, { children: [{ paragraph: "B2" }] }] },
            ],
          },
        },
      ],
    },
  ],
});

Project Philosophy

  1. OOXML Compliance: Strict adherence to the ISO/IEC 29500 OOXML specification
  2. Type Safety: Full TypeScript support with comprehensive types and autocomplete
  3. Pure JSON API: Define documents as plain data objects — zero class instantiation, ideal for AI agents
  4. Performance First: Pure string concatenation for XML generation, native zlib compression, no intermediate AST
  5. Modular Design: Shared core infrastructure across DOCX, PPTX, and XLSX
  6. Cross-Platform: Works in Node.js and browsers. Export to Buffer, Blob, Base64, stream, or string

Development

Prerequisites

  • Node.js 18.x or higher
  • pnpm 9.x or higher (recommended package manager)
  • Git for version control

Getting Started

  1. Clone the repository:

    git clone https://github.com/DemoMacro/office-open.git
    cd office-open
  2. Install dependencies:

    pnpm install
  3. Development mode:

    pnpm dev
  4. Build all packages:

    pnpm build
  5. Test locally:

    # Run tests
    pnpm test

Development Commands

pnpm dev            # Development mode with watch
pnpm build          # Build all packages
pnpm test           # Run tests
pnpm check          # Lint & format

Contributing

We welcome contributions! Here's how to get started:

Quick Setup

  1. Fork the repository on GitHub

  2. Clone your fork:

    git clone https://github.com/YOUR_USERNAME/office-open.git
    cd office-open
  3. Add upstream remote:

    git remote add upstream https://github.com/DemoMacro/office-open.git
  4. Install dependencies:

    pnpm install
  5. Development mode:

    pnpm dev

Development Workflow

  1. Code: Follow our project standards
  2. Test: pnpm build && pnpm test
  3. Commit: Use conventional commits (feat:, fix:, docs:, style:, refactor:, perf:, test:, build:, ci:, chore:, revert:)
  4. Push: Push to your fork
  5. Submit: Create a Pull Request to upstream repository

Support & Community

License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❤️ by Demo Macro

About

The all-in-one TypeScript toolkit for Office documents. Generate, parse, and patch .docx, .pptx, .xlsx files — fully typed, spec-compliant, and works everywhere. Compatible with Microsoft Office, WPS Office, LibreOffice, and Google Workspace.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

 
 
 

Contributors