生成 Office Open XML 文档。

使用 JSON 或 TypeScript 创建 .docx.pptx.xlsx 文件。为 AI 代理和传统开发工作流而设计。
{
    "sections": [
        {
            "children": [
                { "paragraph": { "children": [{ "text": "Hello, World!", "bold": true }] } }
            ]
        }
    ]
}
  • JSON 与 TypeScript
    使用纯 JSON 对象或 TypeScript 函数式 API 创建文档。JSON 优先的设计天然适配 AI 代理、LLM 工作流和 Zod 驱动的 schema。
  • 丰富内容
    段落、表格、图片、图表、SmartArt、数学公式、页眉、页脚等。
  • 类型安全
    全面的 TypeScript 类型定义,为每个 API 提供自动补全和类型安全。
  • 跨平台
    支持 Node.js、浏览器、Deno 和 Bun。可导出为 Buffer、Blob、Base64、流或字符串。
  • 符合 OOXML 规范
    输出通过 OOXML XSD 校验,可在 Microsoft Office、WPS Office、LibreOffice 和 Google Workspace 中打开。
  • 模块化包
    按需安装 — docx、pptx、xlsx、xml 或 core。统一的 office-open 包还提供 CLI 和 AI SDK 工具。

使用 JSON 或 TypeScript 构建文档

将文档定义为纯 JSON 对象——零类实例化——或使用 TypeScript 函数式 API 获得完整的 IDE 体验。两者均生成有效的 OOXML 标记。
  • 创建 Word 文档,支持段落、表格、图片和图表
  • 创建 PowerPoint 演示文稿,支持形状、动画和切换效果
  • 创建 Excel 电子表格,支持样式、图表和数据验证
  • 高性能,原生 zlib 压缩与流式输出
{
    "sections": [
        {
            "children": [
                {
                    "table": {
                        "rows": [
                            { "cells": [{ "children": [{ "paragraph": "Name" }] }, { "children": [{ "paragraph": "Role" }] }] },
                            { "cells": [{ "children": [{ "paragraph": "Alice" }] }, { "children": [{ "paragraph": "Engineer" }] }] },
                            { "cells": [{ "children": [{ "paragraph": "Bob" }] }, { "children": [{ "paragraph": "Designer" }] }] }
                        ]
                    }
                }
            ]
        }
    ]
}

读取和修改现有文件

.docx.pptx.xlsx 文件解析为结构化对象进行检查,或通过替换 {{占位符}} 标记来修补模板。
  • 读取文档结构、样式和内容
  • 替换模板占位符为新内容
  • 解析、修改、重新导出一站式流水线
import { parseDocument, patchDocument } from "@office-open/docx";

// 解析现有文件
const opts = parseDocument(buffer);
// opts.sections — 文档节
// opts.title, opts.creator — 核心属性

// 修补模板占位符
const result = await patchDocument({
  outputType: "nodebuffer",
  data: buffer,
  placeholders: {
    name: { type: "paragraph", children: [{ text: "John" }] },
  },
});

为你的项目添加文档生成能力。

Copyright © 2026