# -*- coding: utf-8 -*- """验证 S1 风格生成物:大纲、表格、图片、版本表、封面。""" from pathlib import Path from docx import Document from docx.oxml.ns import qn OUT = Path(__file__).resolve().parent / "_tmp_docx_out" / "s1style" def check(fname, max_head=40): p = OUT / fname d = Document(str(p)) heads = [x.text.strip() for x in d.paragraphs if x.style.name.startswith(("Heading", "标题")) and x.text.strip()] imgs = sum(1 for x in d.paragraphs if x._element.findall(".//" + qn("w:drawing"))) tbls = len(d.tables) print(f"\n=== {fname} ===") print(f" heads={len(heads)} tables={tbls} images={imgs}") for h in heads[:max_head]: print(" ", h) # 版本表(第一张表)内容 if tbls: t = d.tables[0] print(" T0 hdr:", [c.text.strip() for c in t.rows[0].cells]) for r in t.rows[1:]: print(" |", " | ".join(c.text.strip()[:38] for c in r.cells)) # 封面段落(前 8 个非空) covers = [x.text.strip() for x in d.paragraphs[:12] if x.text.strip()] print(" cover:", covers[:6]) def main(): check("系统集成-用户操作手册-V0.5.docx") check("系统集成模块蓝图设计方案-V0.5.docx") check("九宫格智慧运营看板模块详细设计说明书-V0.1.docx") check("ChatBI智能报表业务需求描述-V0.5.docx") check("运营改善-用户操作手册-V0.5.docx", max_head=20) if __name__ == "__main__": main()