docx
它能做什么
这项技能让 AI 智能体处理 Microsoft Word 文件。适合任何需要创建、修改或读取 Word 文档的人。
适用场景
- ✓当你想创建一份包含标题、表格或页码的新 Word 文档的时候。
- ✓当你需要编辑现有 .docx 文件或从中提取内容的时候。
- ✓当你想处理 Word 文件中的修订标记或批注的时候。
技能链接
https://github.com/agentscope-ai/QwenPaw/blob/main/src/qwenpaw/agents/skills/docx-en/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请把这些会议纪要整理成一份带目录的排版好的 Word 文档。”
每周 5 个新技能,1 分钟读完。
工作原理
它会把 Word 文件当作一组 XML 部件来读取并直接编辑,或者使用文档生成器创建新文件。它还可以转换旧格式文件,并使用常用工具导出文本或 PDF。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Important: All
scripts/paths are relative to this skill directory. Run with:cd {this_skill_dir} && python scripts/...Or use thecwdparameter ofexecute_shell_command.
DOCX creation, editing, and analysis
Prerequisites
- docx (
npm install -g docx): new document creation - LibreOffice (
soffice):.doc->.docxconversion, tracked-changes acceptance, and PDF export - pandoc: text extraction
- pdftoppm (poppler-utils): document-to-image workflows
- If
pdftoppmis unavailable, a Python fallback path may usepdf2image. - On Windows, dependencies must be installed and available in
PATH; if missing, report the dependency issue and stop (do not keep retrying).
Overview
A .docx file is a ZIP archive containing XML files.
Quick Reference
| Task | Approach |
|---|---|
| Read/analyze content | pandoc or unpack for raw XML |
| Create new document | Use docx-js - see Creating New Documents below |
| Edit existing document | Unpack → edit XML → repack - see Editing Existing Documents below |
Converting .doc to .docx
Legacy .doc files must be converted before editing:
python scripts/office/soffice.py --headless --convert-to docx document.doc
Reading Content
# Text extraction with tracked changes
pandoc --track-changes=all document.docx -o output.md
# Raw XML access
python scripts/office/unpack.py document.docx unpacked/
Converting to Images
python scripts/office/soffice.py --headless --convert-to pdf document.docx
pdftoppm -jpeg -r 150 document.pdf page
Accepting Tracked Changes
To produce a clean document with all tracked changes accepted (requires LibreOffice):
python scripts/accept_changes.py input.docx output.docx
Creating New Documents
Generate .docx files with JavaScript, then validate. Install: npm install -g docx
Setup
const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, ImageRun,
Header, Footer, AlignmentType, PageOrientation, LevelFormat, ExternalHyperlink,
TableOfContents, HeadingLevel, BorderStyle, WidthType, ShadingType,
VerticalAlign, PageNumber, PageBreak } = require('docx');
const doc = new Document({ sections: [{ children: [/* content */] }] });
Packer.toBuffer(doc).then(buffer => fs.writeFileSync("doc.docx", buffer));
Validation
After creating the file, validate it. If validation fails, unpack, fix the XML, and repack.
python scripts/office/validate.py doc.docx
Page Size
// CRITICAL: docx-js defaults to A4, not US Letter
// Always set page size explicitly for consistent results
sections: [{
properties: {
page: {
size: {
width: 12240, // 8.5 inches in DXA
height: 15840 // 11 inches in DXA
},
margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } // 1 inch margins
}
},
children: [/* content */]
}]
Common page sizes (DXA units, 1440 DXA = 1 inch):
| Paper | Width | Height | Content Width (1" margins) |
|---|---|---|---|
| US Letter | 12,240 | 15,840 | 9,360 |
| A4 (default) | 11,906 | 16,838 | 9,026 |
Landscape orientation: docx-js swaps width/height internally, so pass portrait dimensions and let it handle the swap:
size: {
width: 12240, // Pass SHORT edge as width
height: 15840, // Pass LONG edge as height
orientation: PageOrientation.LANDSCAPE // docx-js swaps them in the XML
},
// Content width = 15840 - left margin - right margin (uses the long edge)
Styles (Override Built-in Headings)
Use Arial as the default font (universally supported). Keep titles black for readability.
const doc = new Document({
styles: {
default: { document: { run: { font: "Arial", size: 24 } } }, // 12pt default
paragraphStyles: [
// IMPORTANT: Use exact IDs to override built-in styles
{ id: "Heading1", name: "Heading 1", basedOn: "Normal", next: "Normal", quickFormat: true,
run: { size: 32, bold: true, font: "Arial" },
paragraph: { spacing: { before: 240, after: 240 }, outlineLevel: 0 } }, // outlineLevel required for TOC
{ id: "Heading2", name: "Heading 2", basedOn: "Normal", next: "Normal", quickFormat: true,
run: { size: 28, bold: true, font: "Arial" },
paragraph: { spacing: { before: 180, after: 180 }, outlineLevel: 1 } },
]
},
sections: [{
常见问题
它需要额外的软件吗?
需要。它需要安装 docx、LibreOffice 和 pandoc 等工具,并且它们必须在系统路径中可用。
它能处理旧版 .doc 文件吗?
能。旧版 .doc 文件会先用 LibreOffice 转换为 .docx。
它支持 PDF 吗?
不支持。PDF 任务由单独的技能处理。
详情
作者的原始描述
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files). Triggers include: any mention of \"Word doc\", \"word document\", \".docx\", or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a \"report\", \"memo
repo: agentscope-ai/QwenPaw
热度
- GitHub 星标
- 37k
- 排名
- #7576
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
terraform-skill
37k帮你的智能体编写、测试和审查 Terraform 或 OpenTofu 基础设施代码,涵盖模块、CI/CD、安全扫描和状态问题。
computer_use
37k当没有直接工具能完成工作时,让你的智能体通过观察屏幕、点击并检查每一步结果,来操作正在运行的 Windows 或 macOS 应用。
browser
37k通过 QwenPaw Browser SDK 让你的智能体操作真实的网页浏览器,读取页面、对页面执行操作,并在声称成功前检查结果。
channel_message
37k在找到正确的目的地之后,让你的智能体向特定的聊天频道或会话发送单向消息,例如任务完成的提醒。