生成 Office Open XML
文档。
通过声明式 TypeScript API 以编程方式创建
.docx、.pptx 和 .xlsx 文件。支持 Node.js 和浏览器。import { Document, Packer, Paragraph, TextRun } from "@office-open/docx";
const doc = new Document({
sections: [
{
children: [
new Paragraph({
children: [new TextRun({ text: "Hello, World!", bold: true })],
}),
],
},
],
});
const buffer = await Packer.toBuffer(doc);
pnpm add @office-open/docx
声明式 API
使用直观的 TypeScript 类描述文档结构。每个元素映射到有效的 OOXML 标记。
丰富内容
段落、表格、图片、图表、SmartArt、数学公式、页眉、页脚等。
类型安全
完整的类型定义和自动补全,开箱即用。无需额外安装
@types 包。跨平台
支持 Node.js 和浏览器。可导出为 Buffer、Blob、Base64、流或字符串。
符合 OOXML 规范
生成的文件完全符合 ISO/IEC 29500 Office Open XML 规范。
模块化包
按需安装 — docx、pptx、xml 或 core。
用 TypeScript 类构建文档
使用直观的类描述文档结构。每个元素生成有效的 OOXML 标记 — 无需手动编写 XML。
创建 Word 文档,支持段落、表格、图片和图表
创建 PowerPoint 演示文稿,支持形状、动画和切换效果
导出为 Buffer、Blob、Base64、流或字符串
import { Document, Packer, Paragraph, TextRun } from "@office-open/docx";
const doc = new Document({
sections: [
{
children: [
new Paragraph({
children: [new TextRun({ text: "Hello, World!", bold: true })],
}),
],
},
],
});
await Packer.toBuffer(doc);
import { Presentation, Slide, Shape, Paragraph, TextRun, Packer } from "@office-open/pptx";
const pres = new Presentation({
slides: [
new Slide({
children: [
new Shape({
x: 1,
y: 1,
width: 8,
height: 4,
paragraphs: [
new Paragraph({
children: [new TextRun({ text: "Hello, World!", fontSize: 32 })],
}),
],
}),
],
}),
],
});
await Packer.toBuffer(pres);
读取和检查现有文件
将现有的
.docx 和 .pptx 文件解析为结构化对象。检查文档内容、提取数据,或作为修改的基础。读取文档结构、样式和内容
支持 Node.js Buffer 和浏览器 File
解析、修改、重新导出一站式流水线
import { parseDocx } from "@office-open/docx";
const { document, sections, paragraphs } = await parseDocx(buffer);
import { parsePptx } from "@office-open/pptx";
const { slides, shapes } = await parsePptx(buffer);