_verify_s1style_gen.py 1.5 KB

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