docx
БесплатноБез исполняемых скриптовНе проверенThe docx library generates Word (.docx) files from Node.js or the browser in code, with no Word installation: paragraphs, tables, images, headers, footers…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
docx
Overview
docx (npm package, repository dolanmiu/docx, version 9.14.0 when checked on 2026-10-24) builds Word documents declaratively: you create a Document with sections, then serialise it with Packer. It writes new files; it does not edit existing ones. The examples below were run against 9.14.0 and produced a valid .docx.
Instructions
npm install docx
Use ES modules ("type": "module" in package.json) so top-level await works, or wrap the code in an async function.
- Build a
Document({ sections: [{ children: [...] }] }). Section content isParagraphandTableobjects. - Serialise with
await Packer.toBuffer(doc)(Node),Packer.toBlob(doc)(browser) orPacker.toBase64String(doc). - Write the buffer with
fs.writeFileSync.
Things that differ from older tutorials:
ImageRunneedstype("png","jpg","gif","bmp"or"svg"; svg also needs afallbackimage). Omitting it is a TypeScript error. AddaltTextfor accessibility.- Table cell colour is
shading: { type: ShadingType.CLEAR, fill: "1F4E79", color: "auto" }.fillis the cell background; this form was run and produced a valid file. - Lists are not automatic: declare a
numbering.configentry (useLevelFormat.DECIMALorLevelFormat.BULLET) and refer to it withnumbering: { reference, level }on each paragraph. - Use the
HeadingLevelenum (HeadingLevel.HEADING_2), never a string cast toany.
Examples
Example 1: "Generate a monthly report with a table and page numbers"
// report.ts
import {
Document, Packer, Paragraph, TextRun, HeadingLevel, Table, TableRow, TableCell,
WidthType, ShadingType, Footer, PageNumber, AlignmentType,
} from "docx";
import fs from "node:fs";
const cell = (text: string, head = false) =>
new TableCell({
shading: head ? { type: ShadingType.CLEAR, fill: "1F4E79", color: "auto" } : undefined,
children: [new Paragraph({ children: [new TextRun({ text, bold: head, color: head ? "FFFFFF" : undefined })] })],
});
const doc = new Document({
sections: [{
footers: {
default: new Footer({
children: [new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ children: ["Page ", PageNumber.CURRENT, " of ", PageNumber.TOTAL_PAGES] })],
})],
}),
},
children: [
new Paragraph({ heading: HeadingLevel.HEADING_1, text: "Monthly Report" }),
new Paragraph({ children: [new TextRun("Covers "), new TextRun({ text: "September 2026", bold: true }), new TextRun(". Figures are preliminary.")] }),
new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: [
new TableRow({ tableHeader: true, children: [cell("Plan", true), cell("Revenue", true), cell("Growth", true)] }),
new TableRow({ children: [cell("Starter"), cell("$45,000"), cell("+12%")] }),
new TableRow({ children: [cell("Growth"), cell("$32,000"), cell("+8%")] }),
],
}),
],
}],
});
fs.writeFileSync("report.docx", await Packer.toBuffer(doc));
Run npx tsx report.ts; the result is report.docx with a heading, a shaded header row that repeats on page breaks, and "Page 1 of 1" in the footer (Word fills the fields in when it opens the file).
Example 2: "Add a logo, a confidentiality header and a numbered action list"
// proposal.ts
import {
Document, Packer, Paragraph, TextRun, ImageRun, Header, AlignmentType, LevelFormat, HeadingLevel,
} from "docx";
import fs from "node:fs";
const doc = new Document({
numbering: {
config: [
{ reference: "actions", levels: [{ level: 0, format: LevelFormat.DECIMAL, text: "%1.", alignment: AlignmentType.LEFT }] },
{ reference: "bullets", levels: [{ level: 0, format: LevelFormat.BULLET, text: "•", alignment: AlignmentType.LEFT }] },
],
},
sections: [{
headers: {
default: new Header({
children: [new Paragraph({ alignment: AlignmentType.RIGHT, children: [new TextRun({ text: "Confidential", italics: true, color: "999999" })] })],
}),
},
children: [
new Paragraph({
children: [new ImageRun({
type: "png",
data: fs.readFileSync("logo.png"),
transformation: { width: 200, height: 60 },
altText: { name: "logo", title: "Company logo", description: "Northwind Studio logo" },
})],
}),
new Paragraph({ heading: HeadingLevel.HEADING_2, text: "Action items" }),
...["Review Q3 metrics", "Update pricing model", "Schedule team sync"].map(
(item) => new Paragraph({ text: item, numbering: { reference: "actions", level: 0 } }),
),
new Paragraph({ text: "Open question: renewal terms", numbering: { reference: "bullets", level: 0 } }),
],
}],
});
fs.writeFileSync("proposal.docx", await Packer.toBuffer(doc));
The output has the logo at the top, a right-aligned grey "Confidential" header on every page, a numbered li
Установить docx в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл docx?
The docx library generates Word (.docx) files from Node.js or the browser in code, with no Word installation: paragraphs, tables, images, headers, footers, page numbers and numbered or bulleted lists. Use when someone asks to "generate a Word document from data", "create a .docx report in Node", "build a contract or proposal as docx", or "add page numbers to a generated Word file".
Как установить скилл docx?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл docx запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
docx
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
от AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
от Anthropicxlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
от Anthropicpptx
Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…
от Anthropic