Skip to content
Office Open

Getting Started

Command Line Interface (CLI)

Generate Office files from the command line using JSON

The office-open package includes a CLI for generating documents from JSON and detecting or parsing supported Office files.

#Installation

The CLI is included with the office-open package:

pnpm
pnpm add office-open

#Usage

bash
office-open <type> <input> [output]
  • type — Document type: docx, pptx, or xlsx
  • input — JSON string or path to a JSON file
  • output — Output file path (default: output.<ext>)

Generation accepts every OOXML package variant: docx/docm/dotx/dotm, xlsx/xlsm/xltx/xltm, and pptx/pptm/potx/potm.

#Options

FlagAliasDescription
--input-file-iRead JSON from file
--output-file-oOutput file path
--help-hShow help
--version-vShow version

#Examples

#From a JSON file

bash
office-open docx input.json "My Document.docx"

#Using flags

bash
office-open pptx -i slides.json -o "Presentation.pptx"

#Inline JSON

bash
office-open docx '{"sections":[{"children":[{"paragraph":{"children":["Hello, World!"]}}]}]}' "output.docx"

#Detect an input file

bash
office-open detect input.doc
office-open detect input.rtf --json

Detection recognizes OOXML variants, legacy .doc/.xls/.ppt, RTF, and ODF packages.

#Parse an input file

bash
office-open parse input.odt --output model.json

Parsing returns the option family used by the detected input: DocumentOptions, WorkbookOptions, or PresentationOptions. Legacy DOC/XLS/PPT are parse-only; RTF and ODT/ODS/ODP also have dedicated generators.

#JSON Format

Each document type has its own required structure. The CLI validates your input against the corresponding schema before generating.

#DOCX

JSON
{
  "sections": [
    {
      "children": [{ "paragraph": { "children": [{ "text": "Hello, World!", "bold": true }] } }]
    }
  ]
}

#PPTX

JSON
{
  "title": "My Presentation",
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": 100,
            "y": 100,
            "width": 760,
            "height": 340,
            "textBody": {
              "paragraphs": [{ "children": [{ "text": "Hello, World!", "size": 32 }] }]
            }
          }
        }
      ]
    }
  ]
}

#XLSX

JSON
{
  "worksheets": [
    {
      "name": "Sheet1",
      "rows": [
        { "cells": [{ "value": "Name" }, { "value": "Score" }] },
        { "cells": [{ "value": "Alice" }, { "value": 95 }] }
      ]
    }
  ]
}

#Validation

The CLI validates your JSON input before generating. If the input is invalid, you'll get a specific error message with the path and issue:

text
Error: Invalid docx options: at "sections": must be array

#Schema Inspection

The CLI can also consult the JSON Schemas — useful for checking exact field names, enum values, or unit constraints while authoring JSON by hand or through an AI agent:

bash
office-open schema index docx                              # indexed lookup entries by domain
office-open schema index docx --all                        # every definition name
office-open schema slice docx ParagraphOptions RunOptions  # sub-schema for those types

A slice carries the full dependency closure of the requested types; other cataloged domains stay as expandable stubs. Generic definition names need shell quotes: "HeaderFooterGroup<HeaderFooterReference>".

For full schema details, refer to the DOCX, PPTX, and XLSX documentation.