我在docx这个词中计算表格和行的脚本效果很好。我的问题是为什么我的打印声明打印直到条件失败。我附上图片供您参考
这是我的代码:
from docx import Document
doc = Document("sample2.docx")
i = 0
for t in doc.tables:
for ro in t.rows:
if ro.cells[0].text=="Test Type" and (ro.cells[2].text=="Black Box" or ro.cells[2].text=="Black-Box"):
i=i+1
print("Total Black Box Tests are: ", i)
j=0
for table in doc.tables:
for row in table.rows:
if row.cells[0].text=="ID":
j=j+1
print("Total no of Tables:", j)
帮帮我。谢谢!
答案 0 :(得分:1)
上次打印语句缩进的问题 试试这个
from docx import Document
doc = Document("sample2.docx")
i = 0
for t in doc.tables:
for ro in t.rows:
if ro.cells[0].text=="Test Type" and (ro.cells[2].text=="Black Box" or ro.cells[2].text=="Black-Box"):
i=i+1
print("Total Black Box Tests are: ", i)
j=0
for table in doc.tables:
for row in table.rows:
if row.cells[0].text=="ID":
j=j+1
print("Total no of Tables:", j)