技能标识:word-studio
Professional Word document generator. Use when user needs to create reports, papers, contracts, resumes, or any professional document. Supports docx/doc formats, charts, images, tables, TOC, and multi-language. Generates publication-ready documents. Word文档生成、专业报告、论文模板、合同制作。
专业Word文档生成器,可创建符合出版标准的docx/doc格式文档。
请提供以下信息:
文档类型:(报告/论文/简历/合同/其他)
文档标题:
主要内容:
格式要求:(docx/doc)
语言:(中文/英文)
特殊要求:(图表/目录/页眉页脚等)
python
python3 << PYEOF
from docx import Document
from docx.shared import Inches, Pt, Cm, RGBColor, Emu
from docx.enum.text import WDALIGNPARAGRAPH
from docx.enum.table import WDTABLEALIGNMENT
from docx.enum.section import WD_ORIENT
import os
def createcoverpage(doc, config):
创建专业封面,实现垂直居中
section = doc.sections[0]
pageheight = section.pageheight
pagewidth = section.pagewidth
# 创建单列表格用于垂直居中
table = doc.add_table(rows=1, cols=1)
table.alignment = WDTABLEALIGNMENT.CENTER
# 设置表格高度为页面高度(减去边距)
table_row = table.rows[0]
tablerow.height = pageheight - section.topmargin - section.bottommargin
# 获取单元格
cell = table.cell(0, 0)
# 添加标题
title_para = cell.paragraphs[0]
titlepara.alignment = WDALIGN_PARAGRAPH.CENTER
titlerun = titlepara.add_run(config[title])
title_run.font.size = Pt(26)
title_run.font.bold = True
title_run.font.name = 黑体
# 添加空行
cell.add_paragraph()
# 添加副标题
if subtitle in config:
subtitlepara = cell.addparagraph()
subtitlepara.alignment = WDALIGN_PARAGRAPH.CENTER
subtitlerun = subtitlepara.add_run(config[subtitle])
subtitle_run.font.size = Pt(16)
subtitle_run.font.color.rgb = RGBColor(100, 100, 100)
subtitle_run.font.name = 宋体
# 添加空行
cell.add_paragraph()
cell.add_paragraph()
# 添加作者信息
if author in config:
authorpara = cell.addparagraph()
authorpara.alignment = WDALIGN_PARAGRAPH.CENTER
authorrun = authorpara.add_run(config[author])
author_run.font.size = Pt(14)
author_run.font.name = 宋体
# 添加空行
cell.add_paragraph()
# 添加日期
from datetime import datetime
datepara = cell.addparagraph()
datepara.alignment = WDALIGN_PARAGRAPH.CENTER
daterun = datepara.add_run(datetime.now().strftime(%Y年%m月%d日))
date_run.font.size = Pt(14)
date_run.font.name = 宋体
# 隐藏表格边框
from docx.oxml.ns import qn
from docx.oxml import OxmlElement
tbl = table._tbl
tblPr = tbl.tblPr if tbl.tblPr is not None else OxmlElement(w:tblPr)
borders = OxmlElement(w:tblBorders)
for border_name in [top, left, bottom, right, insideH, insideV]:
border = OxmlElement(fw:{border_name})
border.set(qn(w:val), none)
border.set(qn(w:sz), 0)
border.set(qn(w:space), 0)
border.set(qn(w:color), auto)
borders.append(border)
tblPr.append(borders)
return doc
# 添加目录占位符
if config.get(toc, False):
tocheading = doc.addheading(目录, level=1)
tocpara = doc.addparagraph((请在Word中右键此处,选择更新域生成目录))
doc.addpagebreak()
# 添加正文内容
for section_data in config.get(sections, []):
# 添加章节标题
doc.addheading(sectiondata[title], level=1)
# 添加段落内容
for para in section_data.get(paragraphs, []):
p = doc.add_paragraph(para)
p.paragraphformat.firstline_indent = Cm(0.74) # 首行缩进2字符
p.paragraphformat.linespacing = 1.5 # 1.5倍行距
# 添加表格(如有)
if table in section_data:
tabledata = sectiondata[table]
table = doc.addtable(rows=len(tabledata), cols=len(table_data[0]))
table.style = Table Grid
table.alignment = WDTABLEALIGNMENT.CENTER
for i, rowdata in enumerate(tabledata):
for j, celltext in enumerate(rowdata):
table.cell(i, j).text = str(cell_text)
# 添加图片(如有)
if image in section_data:
imgpath = sectiondata[image]
if os.path.exists(img_path):
doc.addpicture(imgpath, width=Inches(5))
last_paragraph = doc.paragraphs[-1]
lastparagraph.alignment = WDALIGN_PARAGRAPH.CENTER
# 添加图表(如有)
if chart in section_data:
chartinfo = sectiondata[chart]
doc.addparagraph(f【图表:{chartinfo[title]}】)
# 添加页眉页脚
if config.get(header, False):
header = section.header
header_para = header.paragraphs[0]
headerpara.text = config.get(headertext, )
headerpara.alignment = WDALIGN_PARAGRAPH.CENTER
if config.get(footer, False):
footer = section.footer
footer_para = footer.paragraphs[0]
footerpara.text = config.get(footertext, )
footerpara.alignment = WDALIGN_PARAGRAPH.CENTER
return doc
def savedocument(doc, outputpath, format=docx):
以指定格式保存文档
if format == doc:
# docx转doc需要LibreOffice
docxpath = outputpath.replace(.doc, .docx)
doc.save(docx_path)
# 尝试使用LibreOffice转换
import subprocess
try:
subprocess.run([
soffice, --headless, --convert-to, doc,
--outdir, os.path.dirname(output_path),
docx_path
以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:
帮我安装 SkillHub 和 word-studio-1776053477 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 word-studio-1776053477 技能
skillhub install word-studio-1776053477
文件大小: 10.29 KB | 发布时间: 2026-4-14 11:47