wps-attendance
考勤打卡统计。把考勤机导出的打卡数据丢进来,自动统计每个人的 迟到、早退、缺勤、加班时长,生成月度考勤汇总表,异常考勤自动标红。 用于帮助HR处理考勤数据。当用户提到考勤、打卡、迟到、加班统计时触发。 Attendance tracker - generates summary reports from…
Word文档生成。用python-docx生成各类Word文档, 支持标题、正文、表格、图片、页眉页脚等元素。 用于帮助用户生成Word文档。当用户提到Word、docx、文档时触发。 Word document generator using python-docx.
$ npx -y skills add Bwkyd/wps-skills --skill wps-docx-writer --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/wps-docx-writerContext 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.
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使用 python-docx 生成各类规范的中文 .docx 文档,兼容 WPS Office 和 Microsoft Word。
| 类型 | 典型场景 | 模板特征 | |------|---------|---------| | **合同/协议** | 劳动合同、租赁合同、保密协议、合作协议 | 甲乙方信息、条款编号、签章区 | | **报告** | 工作报告、调研报告、分析报告、可行性报告 | 封面、目录、章节标题、图表 | | **简历** | 中式求职简历 | 照片位、个人信息表、工作经历 | | **方案/计划** | 项目方案、实施计划、营销方案 | 背景、目标、步骤、预算 | | **论文** | 毕业论文、学术论文 | 封面、摘要、关键词、参考文献 | | **信函** | 商业函件、邀请函、感谢信 | 抬头、正文、落款 | | **表格文档** | 考勤表、登记表、审批表 | 多列表格、合并单元格 |
确认以下信息:
根据文档类型撰写内容,遵循中文商务/学术写作规范。
**先确保依赖已安装:**
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 _42 个 WPS Office 办公自动化 Claude Code Skills 集合 一句话指令,让 Claude 帮你自动生成 Word / Excel / PPT / PDF 文档。
Repo: Bwkyd/wps-skills
考勤打卡统计。把考勤机导出的打卡数据丢进来,自动统计每个人的 迟到、早退、缺勤、加班时长,生成月度考勤汇总表,异常考勤自动标红。 用于帮助HR处理考勤数据。当用户提到考勤、打卡、迟到、加班统计时触发。 Attendance tracker - generates summary reports from…
文档批量格式转换。把一个文件夹里的Word全转文本、Excel全导出CSV、 Markdown转Word,支持docx/txt/xlsx/csv/md等格式批量互转,一次搞定。 用于帮助用户批量转换文档格式。当用户提到批量转换、格式转换、导出时触发。 Batch converts documents between…
预算表一键生成。部门年度预算、项目预算、活动经费预算,选个模板填数字就行, 小计合计公式自动写好,还有预算vs实际对比和执行率自动计算。 用于帮助财务和行政制作预算表。当用户提到预算、费用表、经费时触发。 Budget spreadsheet generator with formulas and variance…
证书奖状批量生成。给一份名单,批量生成荣誉证书、结业证书、聘书、感谢信, 每人一份独立文件,年终评优、培训结业、表彰活动必备工具。 用于帮助用户批量生成证书。当用户提到证书、奖状、聘书时触发。 Batch certificate/award generator from a list of recipients.
数据图表一键生成。不知道数据该用什么图表?告诉我你的数据和目的, 自动推荐最佳图表类型并生成,柱状图折线图饼图散点图都支持,还帮你调配色。 用于帮助用户制作数据可视化图表。当用户提到图表、柱状图、折线图、饼图时触发。 Chart generator - recommends best chart type and…
日历排班值班表。生成带法定节假日和调休标注的月度/年度日历表, 还能做三班倒/两班倒排班表和节假日值班安排,颜色区分不同班次一目了然。 用于帮助用户生成日历和排班表。当用户提到日历、排班、值班、节假日时触发。 Chinese calendar with holidays, shift scheduling, and…