DOCX Skill
Create and edit Microsoft Word documents with rich formatting, tables, images, headers, footers, and tracked changes. Perfect for generating reports, proposals, contracts, and automated document workflows.
Description
This skill enables creating and manipulating .docx Word documents programmatically using the docx npm library. Supports paragraphs, headings, tables, images, lists, page breaks, headers/footers, and styles.
Instructions
When the user asks you to create or edit Word documents, use these patterns:
Creating a Basic Document
const docx = require('docx'); const fs = require('fs'); const doc = new docx.Document({ sections: [{ properties: {}, children: [ new docx.Paragraph({ children: [ new docx.TextRun({ text: 'Project Report', bold: true, size: 48 }), ], heading: docx.HeadingLevel.HEADING_1, }), new docx.Paragraph({ children: [ new docx.TextRun('Generated on: ' + new Date().toLocaleDateString()), ], spacing: { after: 200 }, }), ], }], }); const buffer = await docx.Packer.toBuffer(doc); fs.writeFileSync('report.docx', buffer);
Adding Tables
const table = new docx.Table({ rows: [ new docx.TableRow({ children: [ new docx.TableCell({ children: [new docx.Paragraph('Name')], shading: { fill: '4472C4' }, }), new docx.TableCell({ children: [new docx.Paragraph('Role')], shading: { fill: '4472C4' }, }), ], tableHeader: true, }), new docx.TableRow({ children: [ new docx.TableCell({ children: [new docx.Paragraph('Alice')] }), new docx.TableCell({ children: [new docx.Paragraph('Engineer')] }), ], }), ], width: { size: 100, type: docx.WidthType.PERCENTAGE }, });
Adding Images
const imageBuffer = fs.readFileSync('logo.png'); const image = new docx.ImageRun({ data: imageBuffer, transformation: { width: 200, height: 100 }, type: 'png', }); new docx.Paragraph({ children: [image] });
Bullet Lists
const items = ['First item', 'Second item', 'Third item']; const bullets = items.map(text => new docx.Paragraph({ children: [new docx.TextRun(text)], bullet: { level: 0 }, }));
Rules
- Install dependency first:
npm install docx - The
docxlibrary creates new documents only — it cannot read/parse existing .docx files - To read existing .docx files, use
mammoth(npm install mammoth) for text/HTML extraction - Always use
Packer.toBuffer()for writing (async operation) - Images must be loaded as Buffer, not file paths
- Use
HeadingLevel.HEADING_1throughHEADING_6for proper document structure - Set page margins, orientation, and size via section
properties - For complex layouts, use multiple sections with different properties
Examples
User: Create a project proposal document Action: Generate a formatted .docx with title page, sections, and table of deliverables
User: Convert this markdown to a Word doc Action: Parse the markdown structure, create equivalent docx elements
User: Generate invoices from this data Action: Create a template with header, line-item table, and totals
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Full-Stack Code Reviewer
Comprehensive code review skill that checks for security vulnerabilities, performance issues, accessibility, and best practices across frontend and backend code.
Test Suite Generator
Generates comprehensive test suites with unit tests, integration tests, and edge cases. Supports Jest, Vitest, Pytest, and Go testing.
Pro Architecture Workspace
Battle-tested skill for architectural, decision, making, framework. Includes structured workflows, validation checks, and reusable patterns for development.