SuperAPI AI Directory

docx-generator

Office & productivity

View repository

Updated 10-15 17:26

About this skill

DOCX Generator Skill

A powerful Open Claw Skill for creating Microsoft Word (.docx) documents with an automatically AI-generated disclaimer.

Use Cases

  • Users need to programmatically create Word documents
  • Users want to add an "AI-generated, for reference only" footer to documents
  • Users need to generate reports, documents, or formatted text
  • Users want to create documents with complex formatting (tables, code blocks, images)

Promotion Goals

Call when users explicitly request the following:

  • Generate Word documents
  • Create DOCX files
  • Export content to Word format
  • Produce reports with an AI disclaimer
  • Save formatted text as .docx

File Structure

docx-generator/
├── SKILL.md                    # Skill 配置和文档
└── scripts/
    ├── __init__.py             # 模块导出
    └── docx_generator.py       # 核心实现

Usage

Quick Start

from scripts.docx_generator import create_simple_document

create_simple_document(
    title="我的文档",
    content="文档内容...",
    output_path="./output/document.docx"
)

Create a Report

from scripts.docx_generator import create_report

sections = [
    {"title": "第一章", "content": "第一章的内容"},
    {"title": "第二章", "content": "第二章的内容"}
]

create_report(
    title="报告标题",
    sections=sections,
    output_path="./output/report.docx"
)

Advanced Usage (Chained Calls)

from scripts.docx_generator import DocxGenerator

(DocxGenerator()
    .set_header_text("文档页眉")
    .add_title("文档标题", level=1)
    .add_paragraph("介绍段落", bold=True)
    .add_list(["要点1", "要点2", "要点3"])
    .add_code_block("print('Hello, World!')", language="Python")
    .add_quote("这是一段引用")
    .add_table([["列1", "列2"], ["数据1", "数据2"]])
    .save("./output/advanced.docx"))

Style Control

gen = DocxGenerator()

gen.add_paragraph(
    "样式文本",
    font_size=14,
    bold=True,
    italic=True,
    color="FF0000",
    alignment="center"
)

Features

  • ✅ Automatic Footer: Automatically adds an "AI-generated, for reference only" footer to every page
  • ✅ Rich Content: Supports headings, paragraphs, lists, and tables
  • ✅ Advanced Features: Code blocks, quotes, images, hyperlinks
  • ✅ Header Support: Add custom headers to documents
  • ✅ Chained Calls: Fluent API, more elegant code
  • ✅ Style Control: Font size, color, bold, italic, alignment
  • ✅ Parameter Validation: Comprehensive error checking
  • ✅ Easy to Use: Even beginners can use it easily

API Reference

DocxGenerator Class

Method Description
set_header_text(text) Set the document header
set_footer_text(text) Set the document footer
add_title(title, level=1) Add a heading (level 1-9)
add_paragraph(text, **kwargs) Add a paragraph (optional style)
add_list(items, ordered=False) Add an unordered or ordered list
add_table(data, **kwargs) Add a table
add_code_block(code, language) Add a code block
add_quote(text) Add a quote block
add_image(path, **kwargs) Add an image
add_hyperlink(text, url) Add a hyperlink
add_page_break() Add a page break
add_spacing(lines) Add an empty line
save(filepath) Save the document

Convenience Functions

Function Description
create_simple_document() Quickly create a simple document
create_report() Create a structured report

Dependencies

  • python-docx>=1.1.0

Installation method:

pip install python-docx

Examples

The Skill automatically adds an "AI-generated, for reference only" footer to every page, styled in gray, centered, and italic.

The output document includes:

  • Standard Word document format (.docx)
  • Your content (headings, paragraphs, lists, tables, etc.)
  • An automatically generated AI disclaimer footer

Version

2.0.0