# -*- coding: utf-8 -*- """剖析 S1 模块四份交付文档的格式与风格特征,输出对比基线报告。""" from __future__ import annotations import sys from pathlib import Path from docx import Document from docx.shared import Pt BASE = Path(r"C:\Users\skygu\OneDrive\Projects\AIDOP\项目\项目管理\产互联项目管理\交付文档\Release产互联") S1 = [ "S1产销协同业务需求描述-V0.4.docx", "S1产销协同模块蓝图设计方案-V2.2.docx", "S1产销协同模块详细设计说明书-V1.2.docx", "S1产销协同模块用户操作手册-V1.2.docx", ] MINE = Path(r"C:\Users\skygu\OneDrive\Projects\AIDOP\项目\项目管理\产互联项目管理\交付文档\Release产互联\待确认") MINE_UM = "系统集成-用户操作手册-V0.5.docx" def style_of(p): try: return p.style.name except Exception: return "?" def run_font(p): for r in p.runs: if r.text.strip(): f = r.font sz = f.size.pt if f.size else None return f"{f.name}/{sz}/b={f.bold}" return "-" def dump_doc(path: Path, full: bool): d = Document(str(path)) print(f"\n{'='*70}\nFILE {path.name}") # styles statistics from collections import Counter cnt = Counter(style_of(p) for p in d.paragraphs if p.text.strip()) print("STYLE_STATS", dict(cnt)) # Normal style font try: n = d.styles["Normal"] print("NORMAL_FONT", n.font.name, n.font.size.pt if n.font.size else None) except Exception as e: print("NORMAL_FONT ?", e) # core properties cp = d.core_properties print("CORE title=", cp.title, "| author=", cp.author) # headings outline print("--- HEADINGS ---") for p in d.paragraphs: s = style_of(p) if s.startswith(("Heading", "标题")) and p.text.strip(): print(f" [{s}] {p.text.strip()}") print("--- TABLES ---", len(d.tables)) for i, t in enumerate(d.tables[:6]): hdr = [c.text.strip().replace("\n", "/") for c in t.rows[0].cells] print(f" T{i} rows={len(t.rows)} hdr={hdr[:6]}") if full: print("--- FULL TEXT ---") for p in d.paragraphs: t = p.text.rstrip() if t: print(f"[{style_of(p)}|{run_font(p)}] {t}") for i, t in enumerate(d.tables): print(f"--- TABLE {i} ---") for r in t.rows: print(" | " + " | ".join(c.text.replace("\n", "⏎").strip() for c in r.cells)) def main(): which = sys.argv[1] if len(sys.argv) > 1 else "um" if which == "um": dump_doc(BASE / S1[3], full=True) print("\n\n########## 对比:本次生成的操作手册 ##########") dump_doc(MINE / MINE_UM, full=True) else: idx = {"brd": 0, "bbp": 1, "dds": 2}[which] dump_doc(BASE / idx if isinstance(idx, Path) else BASE / S1[idx], full=False) if __name__ == "__main__": main()