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

Posted 出辞气远鄙倍

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用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) #以列表形式导出每一行数据

 

以上是关于使用python-docx提取word中的表格的主要内容,如果未能解决你的问题,请参考以下文章