关于docx的表格,比如表格中明明有00532这个数字,但是没有找到。
代码如下:
from docx import Document #导入库
a = "00532"
path = "F:\\pycharm\\pythonProject\\engine.docx" #文件路径
document = Document(path) #读入文件
tables = document.tables #获取文件中的表格集
table = tables[0]#获取文件中的第一个表格
for i in range(1, len(table.rows)):#从表格第二行开始循环读取表格数据
if str(table.cell(i, 0).text) == a:
print(table.cell(i, 0).text)
break
else:
print("False")