一键导入
word-python
Word automation using Python + python-docx. Generate, read, and modify Word documents (.docx) with proper formatting.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Word automation using Python + python-docx. Generate, read, and modify Word documents (.docx) with proper formatting.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Ask users questions via the UI. Use when you need clarification, user preferences, or confirmation before proceeding. The user CANNOT see CLI output - this tool is the ONLY way to communicate with them.
数据分析专业指南。当用户提到"分析"、"看看"、"查看"、"统计"、"计算"、"图表"、"报表"、"数据"、"趋势"、"对比"、"汇总"、"平均"、"占比"、"增长"等任何数据相关词汇时必须加载。包含统计方法选择、加权平均计算、数据质量检查、业务洞察提取等最佳实践。适用于 Excel、CSV 等所有数据源的专业分析。
Browser automation with persistent page state. Use when users ask to navigate websites, fill forms, take screenshots, extract web data, test web apps, or automate browser workflows. Trigger phrases include "go to [url]", "click on", "fill out the form", "take a screenshot", "scrape", "automate", "test the website", "log into", or any browser interaction request.
首次激活时的苏醒仪式。当检测到 IDENTITY.md 为空或默认值时触发,引导用户为 agent 取名并建立交流基调。这是最高优先级的流程,必须在任何任务之前完成。
PDF 文件操作技能。使用内置 Python 库读取、提取、生成 PDF。支持表格提取、文本读取、PDF 合并/拆分等。
Excel 修改操作使用 Python + openpyxl
| name | word-python |
| description | Word automation using Python + python-docx. Generate, read, and modify Word documents (.docx) with proper formatting. |
IMPORTANT: This skill uses direct Python scripts instead of MCP tools for better reliability, similar to excel-python.
所有 Word 文档必须使用宋体(SimSun)作为默认字体!
在创建任何文档时,必须为所有文本元素设置字体为宋体!
| Aspect | MCP Tools | Python Scripts |
|---|---|---|
| Reliability | JSON parsing errors common | Stable, predictable |
| Speed | MCP server startup overhead | Direct execution |
| Flexibility | Limited to predefined tools | Full control |
| Debugging | Multi-layer errors | Clear error messages |
| Model-friendly | Complex nested JSON | Natural code |
python3 << 'EOF'
from docx import Document
from docx.shared import Pt
doc = Document()
# Add heading (使用宋体)
heading = doc.add_heading('月度销售报告', 0)
for run in heading.runs:
run.font.name = 'SimSun' # 宋体
run._element.rPr.rFonts.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}eastAsia', 'SimSun')
# Add paragraph (使用宋体)
para = doc.add_paragraph('这是自动生成的报告内容。')
for run in para.runs:
run.font.name = 'SimSun' # 宋体
run._element.rPr.rFonts.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}eastAsia', 'SimSun')
# Save
doc.save('/path/to/report.docx')
print("✅ Word 文档已生成(宋体)")
EOF
python3 << 'EOF'
from docx import Document
from docx.shared import Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH
def set_font_simsun(cell):
"""设置单元格字体为宋体"""
for paragraph in cell.paragraphs:
for run in paragraph.runs:
run.font.name = 'SimSun'
run._element.rPr.rFonts.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}eastAsia', 'SimSun')
doc = Document()
# 标题(宋体)
heading = doc.add_heading('销售数据', 1)
for run in heading.runs:
run.font.name = 'SimSun'
run._element.rPr.rFonts.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}eastAsia', 'SimSun')
# Add table
table = doc.add_table(rows=4, cols=3)
table.style = 'Light Grid Accent 1'
# Header
header_cells = table.rows[0].cells
header_cells[0].text = '产品'
header_cells[1].text = '销量'
header_cells[2].text = '金额'
# 设置表头字体为宋体
for cell in header_cells:
set_font_simsun(cell)
# Data rows
data = [
['产品A', '100', '50000'],
['产品B', '200', '80000'],
['合计', '300', '130000']
]
for i, row_data in enumerate(data, 1):
row_cells = table.rows[i].cells
for j, cell_data in enumerate(row_data):
row_cells[j].text = cell_data
set_font_simsun(row_cells[j]) # 设置宋体
doc.save('/path/to/report.docx')
print("✅ 带表格的报告已生成(宋体)")
EOF
python3 << 'EOF'
from docx import Document
doc = Document('/path/to/file.docx')
# Read all paragraphs
for para in doc.paragraphs:
print(para.text)
# Read all tables
for table in doc.tables:
print("\n表格:")
for row in table.rows:
print([cell.text for cell in row.cells])
EOF
python3 << 'EOF'
from docx import Document
from docx.shared import Pt, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
doc = Document()
# Bold heading
para = doc.add_paragraph('重要提示')
run = para.runs[0]
run.bold = True
run.font.size = Pt(14)
run.font.color.rgb = RGBColor(255, 0, 0)
# Center paragraph
para.alignment = WD_ALIGN_PARAGRAPH.CENTER
doc.save('/path/to/formatted.docx')
print("✅ 格式化文档已生成")
EOF
python3 << 'EOF'
from docx import Document
from docx.shared import Pt
import re
def markdown_to_word(md_content):
doc = Document()
for line in md_content.split('\n'):
if line.startswith('### '):
doc.add_heading(line[4:], 2)
elif line.startswith('## '):
doc.add_heading(line[3:], 1)
elif line.startswith('# '):
doc.add_heading(line[2:], 0)
elif line.strip() == '':
continue
else:
# Remove markdown markers
text = re.sub(r'\*\*(.*?)\*\*', r'\1', line)
text = re.sub(r'\*(.*?)\*', r'\1', text)
text = re.sub(r'`([^`]+)`', r'\1', text)
doc.add_paragraph(text)
return doc
md_text = """
# 报告标题
## 数据分析
这是**重要**数据。
## 结论
关键结论。
"""
doc = markdown_to_word(md_text)
doc.save('/path/to/converted.docx')
print("✅ Markdown 转 Word 完成")
EOF
python3 << 'EOF'
from docx import Document
from docx.shared import Pt, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.styles import ParagraphStyle
doc = Document()
# Title
doc.add_heading('项目进度报告', 0)
# Add table
table = doc.add_table(rows=5, cols=4)
table.style = 'Light Grid Accent 1'
# Header cells
headers = table.rows[0].cells
headers[0].text = '任务'
headers[1].text = '负责人'
headers[2].text = '状态'
headers[3].text = '截止日期'
# Format header
for cell in headers:
run = cell.paragraphs[0].runs[0]
run.bold = True
# Data
data = [
['需求分析', '张三', '已完成', '2024-01-15'],
['UI设计', '李四', '进行中', '2024-01-20'],
['前端开发', '王五', '进行中', '2024-01-25'],
['测试', '赵六', '未开始', '2024-01-30']
]
for i, row_data in enumerate(data, 1):
cells = table.rows[i].cells
for j, cell_data in enumerate(row_data):
cells[j].text = cell_data
doc.save('/path/to/progress.docx')
print("✅ 复杂表格文档已生成")
EOF
| Operation | Code Pattern |
|---|---|
| Create document | doc = Document() |
| Add heading | doc.add_heading('Title', 0) (0=highest) |
| Add paragraph | doc.add_paragraph('Text') |
| Add table | doc.add_table(rows=3, cols=2) |
| Set table style | table.style = 'Light Grid Accent 1' |
| Access cell | table.rows[0].cells[0].text = 'Value' |
| 设置宋体(必须) | run.font.name = 'SimSun' + run._element.rPr.rFonts.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}eastAsia', 'SimSun') |
| Bold text | run.bold = True |
| Font size | run.font.size = Pt(14) |
| Font color | run.font.color.rgb = RGBColor(255, 0, 0) |
| Center align | para.alignment = WD_ALIGN_PARAGRAPH.CENTER |
| Save | doc.save('file.docx') |
def set_simsun_font(run):
"""为 run 设置宋体字体"""
run.font.name = 'SimSun'
run._element.rPr.rFonts.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}eastAsia', 'SimSun')
def set_paragraph_simsun(paragraph):
"""为整个段落设置宋体"""
for run in paragraph.runs:
set_simsun_font(run)
def set_cell_simsun(cell):
"""为表格单元格设置宋体"""
for paragraph in cell.paragraphs:
set_paragraph_simsun(paragraph)
python-docx is pre-installed on most systems. If not:
pip3 install python-docx
ALWAYS request permission before writing:
file-permission_request_file_permission({ "operation": "create", "filePath": "/path/to/report.docx" })