| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- # -*- coding: utf-8 -*-
- """导出无图蓝图(S9/运营诊断/运营改善/系统集成/ChatBI)的正文与表格,供撰写技术方案取材。"""
- import os
- import shutil
- import sys
- import tempfile
- sys.stdout.reconfigure(encoding="utf-8", errors="replace")
- from docx import Document
- from docx.oxml.ns import qn
- from docx.table import Table
- from docx.text.paragraph import Paragraph
- ROOT = r"C:\Users\skygu\OneDrive\Projects\AIDOP\项目\项目管理\产互联项目管理\交付文档"
- OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)),
- "_tmp_bp_text.txt")
- FILES = [
- "S9/S9运营指标与智慧看板模块蓝图设计方案.docx",
- "运营诊断/运营诊断模块蓝图设计方案.docx",
- "运营改善/运营改善模块蓝图设计方案.docx",
- "系统集成/系统集成模块蓝图设计方案.docx",
- "ChatBI/ChatBI智能报表模块蓝图设计方案.docx",
- ]
- tmpdir = tempfile.mkdtemp()
- out = []
- for rel in FILES:
- src = os.path.join(ROOT, rel.replace("/", os.sep))
- local = os.path.join(tmpdir, os.path.basename(src))
- shutil.copy2(src, local)
- doc = Document(local)
- out.append("\n" + "#" * 80)
- out.append(f"### {rel}")
- out.append("#" * 80)
- for el in doc.element.body.iterchildren():
- if el.tag == qn("w:p"):
- p = Paragraph(el, doc)
- t = p.text.strip()
- if not t:
- continue
- s = p.style.name if p.style is not None else ""
- pref = f"[{s}] " if s.startswith(("Heading", "标题")) else ""
- out.append(pref + t)
- elif el.tag == qn("w:tbl"):
- tb = Table(el, doc)
- out.append(f"--- TABLE {len(tb.rows)}x{len(tb.columns)} ---")
- for r in tb.rows:
- seen, cells = set(), []
- for c in r.cells:
- if c._tc in seen:
- continue
- seen.add(c._tc)
- cells.append(c.text.strip().replace("\n", " / "))
- out.append(" | " + " | ".join(cells))
- shutil.rmtree(tmpdir, ignore_errors=True)
- with open(OUT, "w", encoding="utf-8") as f:
- f.write("\n".join(out))
- print(f"导出 {len(FILES)} 份 -> {OUT} ({sum(len(x) for x in out):,} 字符)")
|