使用python-docx提取word中的表格

提取表格

import docx
from docx import Document #导入库

path = '123.docx' #文件路径
document = Document(path) #读入文件
tables = document.tables #获取文件中的表格集

for table in tables[:]:
    for i, row in enumerate(table.rows[:]):   # 读每行
        row_content = []
        for cell in row.cells[:]:  # 读一行中的所有单元格
            c = cell.text
            row_content.append(c)
        print (row_content) #以列表形式导出每一行数据

 

posted @ 2019-12-10 16:14  六盘水月照  阅读(11475)  评论(2编辑  收藏  举报