闲社服务运行正常AI智能体自动化平台
d

Word文档处理

技能标识:docx

Create, read, edit, and manipulate Word documents (.docx). Supports text, tables, images, headers, footers, styles, and tracked changes.

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
1
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

Word文档处理

DOCX 技能 v2.0

概述

使用 docx-js 库创建完整的 Microsoft Word 文档,并通过 XML 操作进行编辑。.docx 文件是一个包含 XML 文件的 ZIP 压缩包。

安装与依赖

必需

bash

创建文档

npm install -g docx

文本提取

brew install pandoc

验证(可选)

pip install python-docx

可选

bash

PDF 转换

brew install --cask libreoffice

图片处理

brew install imagemagick

快速开始

创建第一个文档

javascript const { Document, Packer, Paragraph, TextRun } = require(docx);

const doc = new Document({
sections: [{
children: [
new Paragraph({
children: [
new TextRun({ text: Hello World!, bold: true, size: 32 })
]
})
]
}]
});

await Packer.toBuffer(doc).then(buffer => {
require(fs).writeFileSync(hello.docx, buffer);
});
console.log(✓ 文档已创建!);

读取文档内容

bash

使用 pandoc 提取文本

pandoc document.docx -o output.md

或使用 Python

python -c from docx import Document; doc = Document(file.docx); print(\n.join([p.text for p in doc.paragraphs]))

完整 API 参考

文档结构

javascript
const { Document, Packer, Section } = require(docx);

const doc = new Document({
sections: [{
properties: {
page: {
size: { width: 12240, height: 15840 }, // 美国信纸(DXA 单位)
margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } // 1 英寸
}
},
children: [/ 段落、表格等 /]
}]
});

段落

javascript
const { Paragraph, TextRun, PageBreak } = require(docx);

// 基本段落
new Paragraph({
children: [new TextRun(简单文本)]
})

// 格式化段落
new Paragraph({
children: [
new TextRun({
text: 加粗和 ,
bold: true,
size: 28, // 14pt(size 是半磅值)
font: Arial
}),
new TextRun({
text: 斜体,
italics: true,
color: FF0000 // 十六进制红色
})
],
spacing: {
before: 200, // 段前间距
after: 200, // 段后间距
line: 360 // 行高(1.5 倍 = 360)
},
alignment: center // left, center, right, justified
})

// 标题
new Paragraph({
heading: Heading1,
children: [new TextRun(章节标题)]
})

// 分页符
new Paragraph({
children: [new PageBreak()]
})

列表

javascript
const { LevelFormat } = require(docx);

// 在文档中配置编号
const doc = new Document({
numbering: {
config: [
{
reference: bullet-list,
levels: [{
level: 0,
format: LevelFormat.BULLET,
text: •,
alignment: left,
style: {
paragraph: { indent: { left: 720, hanging: 360 } }
}
}]
},
{
reference: number-list,
levels: [{
level: 0,
format: LevelFormat.DECIMAL,
text: %1.,
alignment: left,
style: {
paragraph: { indent: { left: 720, hanging: 360 } }
}
}]
}
]
},
sections: [{
children: [
// 项目符号列表项
new Paragraph({
numbering: { reference: bullet-list, level: 0 },
children: [new TextRun(项目符号点)]
}),
// 编号列表项
new Paragraph({
numbering: { reference: number-list, level: 0 },
children: [new TextRun(编号项)]
})
]
}]
});

表格

javascript
const { Table, TableRow, TableCell, WidthType, BorderStyle, ShadingType } = require(docx);

// 创建表格
new Table({
width: { size: 9360, type: WidthType.DXA }, // 完整内容宽度
columnWidths: [4680, 4680], // 两个等宽列

rows: [
// 表头行
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ children: [new TextRun(表头 1)] })],
shading: { fill: 4472C4, type: ShadingType.SOLID },
borders: {
top: { style: BorderStyle.SINGLE, size: 1 },
bottom: { style: BorderStyle.SINGLE, size: 1 },
left: { style: BorderStyle.SINGLE, size: 1 },
right: { style: BorderStyle.SINGLE, size: 1 }
}
}),
new TableCell({
children: [new Paragraph({ children: [new TextRun(表头 2)] })],
shading: { fill: 4472C4, type: ShadingType.SOLID },
borders: {
top: { style: BorderStyle.SINGLE, size: 1 },
bottom: { style: BorderStyle.SINGLE, size: 1 },
left: { style: BorderStyle.SINGLE, size: 1 },
right: { style: BorderStyle.SINGLE, size: 1 }
}
})
]
}),
// 数据行
new TableRow({
children: [
new TableCell({
children: [new Paragraph({ children: [new TextRun(数据 1)] })],
borders: {
top: { style: BorderStyle.SINGLE, size: 1 },
bottom: { style: BorderStyle.SINGLE, size: 1 },
left: { style: BorderStyle.SINGLE, size: 1 },
right: { style: BorderStyle.SINGLE, size: 1 }
}
}),
new TableCell({
children: [new Paragraph({ children: [new TextRun(数据 2)] })],
borders: {
top: { style: BorderStyle.SINGLE, size: 1 },
bottom: { style: BorderStyle.SINGLE, size: 1 },
left: { style: BorderStyle.SINGLE, size: 1 },
right: { style: BorderStyle.SINGLE, size: 1 }
}
})
]
})
]
})

图片

javascript
const { ImageRun } = require(docx);
const fs = require(fs);

new Paragraph({
children: [
new ImageRun({
type: png, // 必需:png, jpg, jpeg, gif, bmp, svg
data: fs.readFileSync(image.png),
transformation: {
width: 400,
height: 300
},
altText: {
title: 图片标题,
description: 图片描述,
name: 图片名称
}
})
]
})

页眉和页脚

javascript
const { Header, Footer, PageNumber } = require(docx);

const doc = new Document({
sections: [{
properties: {
page: { margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } }
},
headers: {
default: new Header({
children: [
new Paragraph({
children: [
new TextRun({ text: 文档页眉, bold: true })
],
alignment: center
})
]
})
},
footers: {
default: new Footer({
children: [
new Paragraph({
children: [
new TextRun(第 ),
new TextRun({ children: [PageNumber.CURRENT] }),
new TextRun( 页,共 ),
new TextRun({ children: [PageNumber.TOTAL_PAGES] })
],
alignment: center
})
]
})
},
children: [/ 内容 /]
}]
});

目录

javascript
const { TableOfContents, HeadingLevel } = require(docx);

const doc = new Document({
sections: [{
children: [
// 目录必须位于标题之前
new TableOfContents(目录, {
hyperlink: true,
headingStyleRange:

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 docx-skill-1776104531 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 docx-skill-1776104531 技能

通过命令行安装

skillhub install docx-skill-1776104531

下载

⬇ 下载 docx v1.0.0(免费)

文件大小: 5.37 KB | 发布时间: 2026-4-14 11:37

v1.0.0 最新 2026-4-14 11:37
docx v2.0.0 is a major update with expanded features and improved documentation.

- Adds support for creating, reading, editing, and manipulating Word (.docx) documents, including text, tables, images, headers, footers, styles, and tracked changes.
- Introduces comprehensive examples for working with paragraphs, lists, tables, and images.
- Provides clear installation and dependency guidelines for various document-processing tasks.
- Documents advanced features like headers/footers, tables of contents, and page numbering.
- Utilizes both JavaScript (`docx-js`) for creation and XML for editing.
返回顶部