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 files or JSON strings.
Installation
The CLI is included with the office-open package:
pnpm add office-open
Usage
office-open <type> <input> [output]
- type — Document type:
docx,pptx, orxlsx - input — JSON string or path to a JSON file
- output — Output file path (default:
output.<ext>)
Options
| Flag | Alias | Description |
|---|---|---|
--input-file | -i | Read JSON from file |
--output-file | -o | Output file path |
--help | -h | Show help |
--version | -v | Show version |
Examples
From a JSON file
office-open docx input.json "My Document.docx"
Using flags
office-open pptx -i slides.json -o "Presentation.pptx"
Inline JSON
office-open docx '{"sections":[{"children":[{"paragraph":{"children":["Hello, World!"]}}]}]}' "output.docx"
JSON Format
Each document type has its own required structure. The CLI validates your input against the corresponding schema before generating.
DOCX
{
"sections": [
{
"children": [{ "paragraph": { "children": [{ "text": "Hello, World!", "bold": true }] } }]
}
]
}
PPTX
{
"title": "My Presentation",
"slides": [
{
"children": [
{
"shape": {
"x": 100,
"y": 100,
"width": 760,
"height": 340,
"textBody": { "children": [{ "text": "Hello, World!", "fontSize": 32 }] }
}
}
]
}
]
}
XLSX
{
"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:
Error: Invalid docx options at "sections.0.children.0": Expected object, received string
For full schema details, refer to the DOCX, PPTX, and XLSX documentation.