Tiangong Wps Word Automation — Tiangong Wps Word 自动化
v1.0.0Automate common Word/WPS document operations on Windows via COM (read text, replace, insert, headings, headers/footers, page breaks, merge, split, 导出 to PDF/TXT, 添加/replace images). Use for single-document actions (no batch).
运行时依赖
安装命令
点击复制技能文档
WPS/Word 自动化 (Windows)
Use the bundled Python script to control Word or WPS via COM.
Requirements Windows with Microsoft Word or WPS Writer 安装ed. Python + pywin32 (python -m pip 安装 pywin32). Quick 启动 python {baseDir}/scripts/wps_word_自动化.py read --输入 "C:\path\file.docx" python {baseDir}/scripts/wps_word_自动化.py replace --输入 "C:\path\file.docx" --find "旧" --replace "新" --save "C:\path\out.docx" python {baseDir}/scripts/wps_word_自动化.py 导出 --输入 "C:\path\file.docx" --格式化 pdf --输出 "C:\path\out.pdf"
Commands read
提取 plAIn text.
python {baseDir}/scripts/wps_word_自动化.py read --输入 "C:\path\file.docx" --输出 "C:\path\out.txt"
replace
Find/replace text.
python {baseDir}/scripts/wps_word_自动化.py replace --输入 "C:\path\file.docx" --find "old" --replace "new" --save "C:\path\out.docx"
insert
Insert text at 启动/end.
python {baseDir}/scripts/wps_word_自动化.py insert --输入 "C:\path\file.docx" --text "Hello" --where 启动 --save "C:\path\out.docx"
headings
应用ly Heading 1/2/3 to matching lines.
python {baseDir}/scripts/wps_word_自动化.py headings --输入 "C:\path\file.docx" --level 1 --prefix "# " --save "C:\path\out.docx"
header-footer
设置 header/footer text.
python {baseDir}/scripts/wps_word_自动化.py header-footer --输入 "C:\path\file.docx" --header "标题" --footer "页脚" --save "C:\path\out.docx"
page-break
Insert a page break at the end.
python {baseDir}/scripts/wps_word_自动化.py page-break --输入 "C:\path\file.docx" --save "C:\path\out.docx"
merge
Merge multiple docs into one.
python {baseDir}/scripts/wps_word_自动化.py merge --输入s "a.docx" "b.docx" --输出 "merged.docx"
split
Split by page ranges (e.g., "1-3,4-6").
python {baseDir}/scripts/wps_word_自动化.py split --输入 "C:\path\file.docx" --pages "1-3,4-6" --outdir "C:\out"
导出
导出 to PDF or TXT.
python {baseDir}/scripts/wps_word_自动化.py 导出 --输入 "C:\path\file.docx" --格式化 pdf --输出 "C:\path\out.pdf" python {baseDir}/scripts/wps_word_自动化.py 导出 --输入 "C:\path\file.docx" --格式化 txt --输出 "C:\path\out.txt"
image
添加 or replace image at the end.
python {baseDir}/scripts/wps_word_自动化.py image --输入 "C:\path\file.docx" --image "C:\path\img.png" --save "C:\path\out.docx"
Notes If WPS is 安装ed, try --应用 wps; otherwise default uses Word. Use --visible true if you need to watch the UI. Avoid batch usage; this 技能 is for single-document operations.