← 返回 Skills 市场
happytreees

DOCX Tables

作者 happytreees · GitHub ↗ · v2.0.0 · MIT-0
cross-platform ✓ 安全检测通过
375
总下载
0
收藏
0
当前安装
2
版本数
在 OpenClaw 中安装
/install docx-tables
功能描述
Create Word documents with properly formatted tables using docx npm library. Tables work consistently across Word and Google Docs. Use when creating DOCX fil...
使用说明 (SKILL.md)

docx-tables

Create Word documents with tables that work everywhere - Word, Google Docs, etc.

⚠️ THE 5 CRITICAL RULES

1. Dual-Width Sizing (MOST CRITICAL)

Set widths in TWO places - on table AND on each cell:

// Table level
new Table({
  width: { size: 9360, type: WidthType.DXA },
  columnWidths: [1872, 7488],
  rows: [...]
})

// Cell level - EVERY cell needs width!
new TableCell({
  width: { size: 1872, type: WidthType.DXA },
  children: [...]
})

2. Use DXA Only, Never Percentages

Percentages break in Google Docs. Use DXA:

  • 1 inch = 1440 DXA
  • US Letter with 1" margins = 9360 DXA
// ❌ WRONG
width: { size: 100, type: WidthType.PERCENTAGE }

// ✅ CORRECT
width: { size: 9360, type: WidthType.DXA }

3. Use ShadingType.CLEAR

const { ShadingType } = require('docx');

// ❌ WRONG - black background!
shading: { type: ShadingType.SOLID, fill: "E0F2F1" }

// ✅ CORRECT
shading: { type: ShadingType.CLEAR, fill: "E0F2F1" }

4. Add Cell Padding

const cellMargins = { top: 80, bottom: 80, left: 120, right: 120 };

new TableCell({
  margins: cellMargins,
  children: [...]
})

5. Column Widths Must Sum Exactly

For 1" margins: 9360 DXA

columnWidths: [1872, 7488]  // = 9360 ✓
columnWidths: [3120, 3120, 3120]  // = 9360 ✓

Complete Working Example

const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, 
         WidthType, AlignmentType, BorderStyle, TableLayoutType, ShadingType } = require('docx');
const fs = require('fs');

const TOTAL_WIDTH = 9360;
const COL1 = 1872;
const COL2 = 7488;

const cellBorders = {
  top: { style: BorderStyle.SINGLE, size: 1, color: "CCCCCC" },
  bottom: { style: BorderStyle.SINGLE, size: 1, color: "CCCCCC" },
  left: { style: BorderStyle.SINGLE, size: 1, color: "CCCCCC" },
  right: { style: BorderStyle.SINGLE, size: 1, color: "CCCCCC" }
};

const cellMargins = { top: 80, bottom: 80, left: 120, right: 120 };

const doc = new Document({
  sections: [{
    properties: { 
      page: { margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } }
    },
    children: [
      new Table({
        layout: TableLayoutType.FIXED,
        width: { size: TOTAL_WIDTH, type: WidthType.DXA },
        columnWidths: [COL1, COL2],
        rows: [
          new TableRow({
            children: [
              new TableCell({
                children: [new Paragraph({ 
                  children: [new TextRun({ text: "Header", bold: true, color: "FFFFFF" })],
                  alignment: AlignmentType.CENTER
                })],
                width: { size: TOTAL_WIDTH, type: WidthType.DXA },
                columnSpan: 2,
                shading: { type: ShadingType.CLEAR, fill: "1565C0" },
                borders: cellBorders,
                margins: cellMargins
              })
            ]
          }),
          new TableRow({
            children: [
              new TableCell({
                children: [new Paragraph("Col 1")],
                width: { size: COL1, type: WidthType.DXA },
                borders: cellBorders,
                margins: cellMargins
              }),
              new TableCell({
                children: [new Paragraph("Col 2")],
                width: { size: COL2, type: WidthType.DXA },
                borders: cellBorders,
                margins: cellMargins
              })
            ]
          })
        ]
      })
    ]
  }]
});

Packer.toBuffer(doc).then(buffer => {
  fs.writeFileSync('output.docx', buffer);
});

Column Width Cheat Sheet

For US Letter with 1" margins = 9360 DXA:

Layout Column Widths
2 cols (20/80) [1872, 7488]
2 cols (25/75) [2340, 7020]
2 cols (equal) [4680, 4680]
3 cols (equal) [3120, 3120, 3120]
3 cols (25/25/50) [2340, 2340, 4680]

Troubleshooting

Tables narrow in Google Docs?

  • Use WidthType.DXA, not PERCENTAGE
  • Add width to EVERY TableCell

Cell backgrounds black?

  • Use ShadingType.CLEAR, not SOLID

Text touching borders?

  • Add margins: { top: 80, bottom: 80, left: 120, right: 120 }

Columns uneven?

  • Verify column widths sum to exactly 9360
安全使用建议
This is an instructional skill that provides best-practice rules and a ready Node.js example for building DOCX tables with the 'docx' package. It does not request credentials or install anything itself. Before using: ensure you run the example in a safe environment with Node.js and the 'docx' npm package installed (npm install docx), be aware it will write output.docx to the working directory, and review any code you paste/run to avoid executing untrusted scripts. If you want the agent to execute the example automatically, verify the runtime has Node and the docx package available — the skill itself does not install dependencies.
功能分析
Type: OpenClaw Skill Name: docx-tables Version: 2.0.0 The skill bundle provides legitimate technical instructions and code examples for generating Word documents with tables using the 'docx' npm library. The content in SKILL.md focuses entirely on formatting compatibility (e.g., using DXA units and specific shading types) and lacks any indicators of data exfiltration, malicious execution, or prompt injection.
能力评估
Purpose & Capability
Name/description match the SKILL.md content: guidance and a complete Node.js example for creating Word tables with the 'docx' library. It does not request unrelated credentials, binaries, or config paths.
Instruction Scope
Instructions are narrowly focused on table formatting rules and a concrete Node.js example that writes 'output.docx' to the current directory. This is expected, but the doc assumes the 'docx' npm package and a Node.js runtime exist; the skill does not provide an install step or recommend installing the package.
Install Mechanism
No install spec and no code files — lowest-risk pattern. The SKILL.md contains example code only; nothing is downloaded or written by the skill itself.
Credentials
The skill declares no environment variables, credentials, or config paths and the instructions do not request secrets or external service tokens. File write (output.docx) is limited and consistent with purpose.
Persistence & Privilege
always is false and there are no indications the skill requests persistent system presence or modifies other skills/config. Agent autonomy is default and not a special privilege here.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install docx-tables
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /docx-tables 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v2.0.0
**Major update: Now uses the docx npm library instead of python-docx, with focus on consistent table rendering across Word and Google Docs.** - Switched from python-docx to docx (npm) for DOCX table generation. - Added clear rules for full-width tables that work in both Word and Google Docs: always set widths on both tables and cells, use DXA units only, sum column widths exactly, and use ShadingType.CLEAR. - Provided concise code examples and a complete usage demo in JavaScript. - Included troubleshooting advice and width cheat sheet for common layouts.
v1.0.0
Initial release of docx-tables. - Create Word documents with full-width, explicitly sized tables using python-docx. - Supports setting column widths, disabling autofit, and table alignment. - Includes utilities for setting margins, cell background colors, and merging cells. - Provides examples for itineraries, schedules, data tables, and highlights. - Troubleshooting tips for common Word table issues.
元数据
Slug docx-tables
版本 2.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 2
常见问题

DOCX Tables 是什么?

Create Word documents with properly formatted tables using docx npm library. Tables work consistently across Word and Google Docs. Use when creating DOCX fil... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 375 次。

如何安装 DOCX Tables?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install docx-tables」即可一键安装,无需额外配置。

DOCX Tables 是免费的吗?

是的,DOCX Tables 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

DOCX Tables 支持哪些平台?

DOCX Tables 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 DOCX Tables?

由 happytreees(@happytreees)开发并维护,当前版本 v2.0.0。

💬 留言讨论