AnyBot/skills/docx/SKILL.md

50 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
name: docx
description: >-
建立、編輯或轉換正式 Word 文件(.docx),包含企劃書、報告、會議紀錄、SOP、公文與合約排版。當使用者指名要 Word 檔、.docx 或需要可編輯的正式文件檔案時,先載入本技能。
---
# Word 正式文件(.docx)編排指南
產出或修改 `.docx` 時,目標是做出「打開就能直接寄給客戶或主管」的乾淨排版,避免預設藍字標題、擁擠表格與中英字型不一致。
## 1. 關鍵排版規範(`python-docx`)
1. **必須同時設定西文與東亞(繁中)字型**:
只設 `run.font.name` 在 Word 裡中文字仍會退回新細明體!務必同時指定 `w:eastAsia`:
```python
from docx.oxml.ns import qn
from docx.shared import Pt, RGBColor, Mm
def set_cjk_font(style_or_run, en_font="Inter", zh_font="Microsoft JhengHei", size_pt=11, color=(24, 24, 27)):
f = style_or_run.font
f.name = en_font
f.size = Pt(size_pt)
f.color.rgb = RGBColor(*color)
rPr = style_or_run._element.get_or_add_rPr()
rFonts = rPr.get_or_add_rFonts()
rFonts.set(qn("w:eastAsia"), zh_font)
```
2. **頁面邊界與行距**:
- A4 紙張(`section.page_width = Mm(210)`, `section.page_height = Mm(297)`),上下邊界 `22mm`、左右邊界 `22mm`。
- 內文行距 `1.4–1.5` 倍、段後間距 `6pt`;標題設定 `keep_with_next = True` 防止標題孤立在頁尾。
3. **色彩與階層**:
- 主標題(H1):`18–20pt` 粗體深色 `#0F172A`
- 章節標題(H2):`14pt` 粗體 `#1E293B`(段前 `14pt`、段後 `4pt`)
- 小節標題(H3):`12pt` 粗體 `#334155`
- 內文:`10.5–11pt` `#18181B`;輔助說明/頁首頁尾:`9pt` `#71717A`
4. **表格留白與框線**:
- 避免預設粗黑格線;改用淺灰橫線 `#E4E4E7`、深色或淺灰表頭底色 `#F4F4F5`,並為儲存格設定上下左右內距(cell margins `top/bottom=100 dxa, left/right=140 dxa`),文字才不會貼死格線。
5. **編輯既有 `.docx` 檔案時**:
- 先用 `read_file` 或 `python-docx` 讀出段落與表格結構;保留原文件的樣式與頁首頁尾,只精準修改目標段落文字(注意替換時修改特定 `run` 以保留粗體/斜體格式)。
## 2. 交付前檢查(`scripts/audit_docx.py`)
產出 `.docx` 後,執行隨附的 `scripts/audit_docx.py`(可用 `use_skill` 帶 `file: "scripts/audit_docx.py"` 讀取)檢查段落數、空白頁風險、是否漏設東亞字型與未替換的 `{{placeholder}}`:
```bash
python3 audit_docx.py output.docx
```
若系統有安裝 LibreOffice + `pdftoppm`,可再執行 `soffice --headless --convert-to pdf output.docx` 轉圖抽查版面,最後以 `send_file` 傳送檔案。