Skip to content
Automation
Skill

/wps-docx-writer

Word文档生成。用python-docx生成各类Word文档, 支持标题、正文、表格、图片、页眉页脚等元素。 用于帮助用户生成Word文档。当用户提到Word、docx、文档时触发。 Word document generator using python-docx.

From plugin
bwkyd-wps-skills
842 skills
Install
$ npx -y skills add Bwkyd/wps-skills --skill wps-docx-writer --agent claude-code

How it fires

How this skill gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.
  • Slash command/wps-docx-writer

Context preview

The summary Claude sees to decide when to auto-load this skill.

Word文档生成。用python-docx生成各类Word文档, 支持标题、正文、表格、图片、页眉页脚等元素。 用于帮助用户生成Word文档。当用户提到Word、docx、文档时触发。 Word document generator using python-docx.

SKILL.md

wps-docx-writer.SKILL.md
name: wps-docx-writer
description: |
  Word文档生成。用python-docx生成各类Word文档,
  支持标题、正文、表格、图片、页眉页脚等元素。
  用于帮助用户生成Word文档。当用户提到Word、docx、文档时触发。
  Word document generator using python-docx.
license: MIT
user-invocable: true
argument-hint: '[文档类型] [内容描述]'
allowed-tools: 'Read, Grep, Glob, Bash, Write, Edit'
metadata:
  author: BWKYD
  title: Word文档生成
  description_zh: 用python-docx生成Word文档,支持标题、正文、表格、图片等
  tags:
    - Word
    - docx
    - python-docx
    - 文档生成
    - WPS
  version: 1.0.3
  license: MIT

Word 文档生成器

使用 python-docx 生成各类规范的中文 .docx 文档,兼容 WPS Office 和 Microsoft Word。

When to Use

  • 用户需要生成 Word/docx 文档
  • 用户需要创建合同、报告、简历、论文、方案等
  • 用户需要批量生成文档或填充模板
  • 用户说"帮我写一份XX"且不是公文场景

When NOT to Use

  • 党政机关公文 → 使用 `wps-gongwen`
  • WPS宏脚本开发 → 使用 `wps-jsa-macro`
  • 纯文本/Markdown文档 → 直接编写

支持的文档类型

| 类型 | 典型场景 | 模板特征 | |------|---------|---------| | **合同/协议** | 劳动合同、租赁合同、保密协议、合作协议 | 甲乙方信息、条款编号、签章区 | | **报告** | 工作报告、调研报告、分析报告、可行性报告 | 封面、目录、章节标题、图表 | | **简历** | 中式求职简历 | 照片位、个人信息表、工作经历 | | **方案/计划** | 项目方案、实施计划、营销方案 | 背景、目标、步骤、预算 | | **论文** | 毕业论文、学术论文 | 封面、摘要、关键词、参考文献 | | **信函** | 商业函件、邀请函、感谢信 | 抬头、正文、落款 | | **表格文档** | 考勤表、登记表、审批表 | 多列表格、合并单元格 |

工作流程

Step 1: 需求确认

确认以下信息:

  • **文档类型**:合同/报告/简历/方案/论文/信函/其他
  • **主要内容**:核心内容描述
  • **特殊要求**:页面方向、字体偏好、是否需要封面/目录等

Step 2: 内容撰写

根据文档类型撰写内容,遵循中文商务/学术写作规范。

Step 3: 生成 .docx 文件

**先确保依赖已安装:**

pip install python-docx 2>/dev/null || pip3 install python-docx 2>/dev/null

**使用以下核心代码框架:**

from docx import Document
from docx.shared import Pt, Mm, Cm, Inches, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.enum.table import WD_TABLE_ALIGNMENT
from docx.enum.section import WD_ORIENT
from docx.oxml.ns import qn, nsdecls
from docx.oxml import parse_xml
import os

class DocxWriter:
    """通用中文docx文档生成器"""

    # 预置样式
    STYLES = {
        'title':    {'font': '方正小标宋简体', 'size': 22, 'bold': True,  'align': 'CENTER'},
        'heading1': {'font': '黑体',           'size': 18, 'bold': True,  'align': 'LEFT'},
        'heading2': {'font': '黑体',           'size': 16, 'bold': True,  'align': 'LEFT'},
        'heading3': {'font': '黑体',           'size': 14, 'bold': True,  'align': 'LEFT'},
        'body':     {'font': '仿宋_GB2312',    'size': 12, 'bold': False, 'align': 'JUSTIFY'},
        'body_song':{'font': '宋体',           'size': 12, 'bold': False, 'align': 'JUSTIFY'},
        'small':    {'font': '宋体',           'size': 10.5,'bold': False, 'align': 'LEFT'},
        'footer':   {'font': '宋体',           'size': 9,  'bold': False, 'align': 'CENTER'},
    }

    def __init__(self, page='A4', orientation='portrait', margins=None):
        self.doc = Document()
        section = self.doc.sections[0]

        # 页面设置
        if orientation == 'landscape':
            section.orientation = WD_ORIENT.LANDSCAPE
            section.page_width = Mm(297)
            section.page_height = Mm(210)
        else:
            section.page_width = Mm(210)
            section.page_height = Mm(297)

        # 边距(默认普通边距)
        m = margins or {'top': 25.4, 'bottom': 25.4, 'left': 31.8, 'right': 31.8}
        section.top_margin = Mm(m['top'])
        section.bottom_margin = Mm(m['bottom'])
        section.left_margin = Mm(m['left'])
        section.right_margin = Mm(m['right'])

    def add_text(self, text, style='body', space_before=0, space_after=0,
                 first_indent=None, line_spacing=None, color=None):
        """添加格式化段落"""
        s = self.STYLES.get(style, self.STYLES['body'])
        p = self.doc.add_paragraph()
        p.alignment = getattr(WD_ALIGN_PARAGRAPH, s['align'])
        p.paragraph_format.space_before = Pt(space_before)
        p.paragraph_format.space_after = Pt(space_after)
        if line_spacing:
            p.paragraph_format.line_spacing = Pt(line_spacing)
        if first_indent is not None:
            p.paragraph_format.first_line_indent = Pt(first_indent)
        elif style == 'body' or style == 'body_song':
            p.paragraph_format.first_line_indent = Pt(s['size'] * 2)

        run = p.add_run(text)
        run.font.size = Pt(s['size'])
        run.font.name = s['font']
        run._element.rPr.rFonts.set(qn('w:eastAsia'), s['font'])
        run.bold = s['bold']
        if color:
            run.font.color.rgb = RGBColor(*color)
        return p

    def add_table(self, headers, rows, col_widths=None, style='Table Grid'):
        """添加表格"""
        table = self.doc.add_table(rows=1 + len(rows), cols=len(headers), style=style)
        table.alignment = WD_TABLE_ALIGNMENT.CENTER

        # 表头
        for i, header in enumerate(headers):
            cell = table.rows[0].cells[i]
            cell.text = header
            for paragraph in cell.paragraphs:
                paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
                for run in paragraph.runs:
                    run.bold = True
                    run.font.size = Pt(10.5)
                    run.font.name = '黑体'
                    run._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')

        # 数据行
        for r_idx, row_data in enumerate(rows):
            for c_idx, cell_text in enumerate(row_data):
                cell = table.rows[r_idx + 1].cells[c_idx]
                cell.text = str(cell_text)
                for paragraph in cell.paragraphs:
                    paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
                    for run in paragraph.runs:
                        run.font.size = Pt(10.5)
                        run.font.name = '宋体'
                        run._element.rPr.rFonts.set(qn('w:eastAsia'), '宋体')

        # 列宽
        if col_widths:
            for i, width in enumerate(col_widths):
                for row in table.rows:
                    row.cells[i].width = Mm(width)

        return table

    def add_page_break(self):
        """添加分页符"""
        self.doc.add_page_break()

    def add_cover(self, title, subtitle=None, org=None, date_str=None):
        """添加封面页"""
        # 上方留白
        for _
Read more
Ships withbwkyd-wps-skills

42 个 WPS Office 办公自动化 Claude Code Skills 集合 一句话指令,让 Claude 帮你自动生成 Word / Excel / PPT / PDF 文档。

Get the whole plugin

Other skills on bwkyd-wps-skills.

wps-attendance
Skill

wps-attendance

考勤打卡统计。把考勤机导出的打卡数据丢进来,自动统计每个人的 迟到、早退、缺勤、加班时长,生成月度考勤汇总表,异常考勤自动标红。 用于帮助HR处理考勤数据。当用户提到考勤、打卡、迟到、加班统计时触发。 Attendance tracker - generates summary reports from…

wps-batch-convert
Skill

wps-batch-convert

文档批量格式转换。把一个文件夹里的Word全转文本、Excel全导出CSV、 Markdown转Word,支持docx/txt/xlsx/csv/md等格式批量互转,一次搞定。 用于帮助用户批量转换文档格式。当用户提到批量转换、格式转换、导出时触发。 Batch converts documents between…

wps-budget
Skill

wps-budget

预算表一键生成。部门年度预算、项目预算、活动经费预算,选个模板填数字就行, 小计合计公式自动写好,还有预算vs实际对比和执行率自动计算。 用于帮助财务和行政制作预算表。当用户提到预算、费用表、经费时触发。 Budget spreadsheet generator with formulas and variance…

wps-certificate
Skill

wps-certificate

证书奖状批量生成。给一份名单,批量生成荣誉证书、结业证书、聘书、感谢信, 每人一份独立文件,年终评优、培训结业、表彰活动必备工具。 用于帮助用户批量生成证书。当用户提到证书、奖状、聘书时触发。 Batch certificate/award generator from a list of recipients.

wps-chart
Skill

wps-chart

数据图表一键生成。不知道数据该用什么图表?告诉我你的数据和目的, 自动推荐最佳图表类型并生成,柱状图折线图饼图散点图都支持,还帮你调配色。 用于帮助用户制作数据可视化图表。当用户提到图表、柱状图、折线图、饼图时触发。 Chart generator - recommends best chart type and…

wps-cn-calendar
Skill

wps-cn-calendar

日历排班值班表。生成带法定节假日和调休标注的月度/年度日历表, 还能做三班倒/两班倒排班表和节假日值班安排,颜色区分不同班次一目了然。 用于帮助用户生成日历和排班表。当用户提到日历、排班、值班、节假日时触发。 Chinese calendar with holidays, shift scheduling, and…