31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from docx import Document
|
|
from pathlib import Path
|
|
|
|
# 打开模板
|
|
template_path = Path(r"C:\PPRO\PCM_Report\configs\600泵\template.docx")
|
|
doc = Document(str(template_path))
|
|
|
|
print(f"文档中的表格数量: {len(doc.tables)}")
|
|
|
|
# 查找 scriptTable1
|
|
token = "scriptTable1"
|
|
found = False
|
|
for ti, table in enumerate(doc.tables):
|
|
print(f"\n表格 {ti}: {len(table.rows)} 行 x {len(table.rows[0].cells) if table.rows else 0} 列")
|
|
for ri, row in enumerate(table.rows):
|
|
for ci, cell in enumerate(row.cells):
|
|
if token in cell.text:
|
|
print(f" 找到 {token} 在行 {ri}, 列 {ci}")
|
|
print(f" 单元格文本: {cell.text[:50]}")
|
|
found = True
|
|
|
|
if not found:
|
|
print(f"\n未找到 {token}")
|
|
print("\n检查所有单元格文本:")
|
|
for ti, table in enumerate(doc.tables):
|
|
for ri in range(min(3, len(table.rows))):
|
|
for ci in range(min(5, len(table.rows[ri].cells))):
|
|
text = table.rows[ri].cells[ci].text
|
|
if text.strip():
|
|
print(f" 表{ti} 行{ri} 列{ci}: {text[:30]}")
|