0
0
# Install this skill:
npx skills add TheSimpleApp/agent-skills --skill "docx"

Install specific skill from multi-skill repository

# Description

Create and edit Word documents with formatting, styles, tables, and images. Use when working with Word files, generating reports, or document automation.

# SKILL.md


name: docx
description: Create and edit Word documents with formatting, styles, tables, and images. Use when working with Word files, generating reports, or document automation.
license: MIT
metadata:
author: thesimpleapp
version: "1.0"


Word Document Processing

Create and manipulate Word documents with python-docx.

Python Library: python-docx

pip install python-docx

Basic Document Creation

from docx import Document
from docx.shared import Inches, Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH

# Create document
doc = Document()

# Add title
doc.add_heading('Document Title', 0)

# Add paragraph
para = doc.add_paragraph('This is a paragraph with ')
para.add_run('bold text').bold = True
para.add_run(' and ')
para.add_run('italic text').italic = True

# Save
doc.save('output.docx')

Headings and Structure

doc.add_heading('Chapter 1', level=1)
doc.add_heading('Section 1.1', level=2)
doc.add_heading('Subsection 1.1.1', level=3)

doc.add_paragraph('Regular paragraph text.')

Tables

# Create table
table = doc.add_table(rows=3, cols=3)
table.style = 'Table Grid'

# Header row
header_cells = table.rows[0].cells
header_cells[0].text = 'Name'
header_cells[1].text = 'Quantity'
header_cells[2].text = 'Price'

# Data rows
data = [
    ('Item 1', '10', '$100'),
    ('Item 2', '20', '$200'),
]
for i, row_data in enumerate(data, start=1):
    row = table.rows[i].cells
    for j, value in enumerate(row_data):
        row[j].text = value

Lists

# Bullet list
doc.add_paragraph('First item', style='List Bullet')
doc.add_paragraph('Second item', style='List Bullet')

# Numbered list
doc.add_paragraph('Step one', style='List Number')
doc.add_paragraph('Step two', style='List Number')

Images

doc.add_picture('image.png', width=Inches(4))

# Or with specific dimensions
doc.add_picture('logo.png', width=Inches(2), height=Inches(1))

Formatting

from docx.shared import Pt, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH

para = doc.add_paragraph()
run = para.add_run('Formatted text')

# Font properties
run.font.name = 'Arial'
run.font.size = Pt(14)
run.font.bold = True
run.font.color.rgb = RGBColor(0x00, 0x00, 0xFF)

# Paragraph alignment
para.alignment = WD_ALIGN_PARAGRAPH.CENTER

Page Layout

from docx.shared import Inches

section = doc.sections[0]

# Page size (Letter)
section.page_width = Inches(8.5)
section.page_height = Inches(11)

# Margins
section.left_margin = Inches(1)
section.right_margin = Inches(1)
section.top_margin = Inches(1)
section.bottom_margin = Inches(1)

Headers and Footers

section = doc.sections[0]

# Header
header = section.header
header.paragraphs[0].text = "Document Header"

# Footer
footer = section.footer
footer.paragraphs[0].text = "Page "
# Add page number
from docx.oxml.ns import qn
from docx.oxml import OxmlElement

Reading Existing Documents

doc = Document('existing.docx')

# Iterate paragraphs
for para in doc.paragraphs:
    print(para.text)

# Iterate tables
for table in doc.tables:
    for row in table.rows:
        for cell in row.cells:
            print(cell.text)

Best Practices

  1. Use styles for consistent formatting
  2. Template documents - Start from a styled template
  3. Handle encoding - Ensure proper text encoding
  4. Test output - Open in Word to verify rendering
  5. Track changes - Use revision marking for edits

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.